All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ColorPickerToolButton.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 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_popup->setSelected(color);
51  m_selectedColor = color;
52  updateIcon();
53 }
54 
56 {
57  return m_selectedColor;
58 }
59 
61 {
62  QToolButton::resizeEvent(e);
63  updateIcon();
64 }
65 
67 {
68  m_popup->move(mapToGlobal(QPoint(0, height())));
69  m_popup->show();
70 }
71 
73 {
74  QPixmap pix(iconSize());
75  pix.fill(m_selectedColor);
76  QPainter p(&pix);
77  p.setPen(QPen(Qt::darkGray, 2));
78  p.drawRect(pix.rect());
79  setIcon(pix);
80 }
81 
83 {
84  setColor(color);
85  emit colorChanged(color);
86 }
Create a frame with a default color palette.
Custom widget used to pick a color.