All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ColorPickerToolButton.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/utils/ColorPickerToolButton.cpp
22 
23  \brief Custom widget used to pick a color.
24 */
25 
26 // TerraLib
27 #include "ColorPickerToolButton.h"
28 
30  : QToolButton(parent),
31  m_popup(new ColorPickerPopup)
32 {
33  setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
34  setPopupMode(QToolButton::MenuButtonPopup);
35  setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
36  setText(tr("Color"));
37  setIconSize(QSize(16, 16));
38  setColor(Qt::black);
39 
40  // Signals & slots
41  connect(m_popup, SIGNAL(selected(const QColor&)), this, SLOT(onPopupSelected(const QColor&)));
42 }
43 
45 {
46 }
47 
49 {
50  m_selectedColor = color;
51  updateIcon();
52 }
53 
55 {
56  return m_selectedColor;
57 }
58 
60 {
61  QToolButton::resizeEvent(e);
62  updateIcon();
63 }
64 
66 {
67  m_popup->move(mapToGlobal(QPoint(0, height())));
68  m_popup->show();
69 }
70 
72 {
73  QPixmap pix(iconSize());
74  pix.fill(m_selectedColor);
75  QPainter p(&pix);
76  p.setPen(QPen(Qt::darkGray, 2));
77  p.drawRect(pix.rect());
78  setIcon(pix);
79 }
80 
82 {
83  setColor(color);
84  emit colorChanged(color);
85 }
Create a frame with a default color palette.
Custom widget used to pick a color.