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  m_isOpen(false)
33 {
34  setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
35  setPopupMode(QToolButton::MenuButtonPopup);
36  setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
37  setText(tr("Color"));
38  setIconSize(QSize(16, 16));
39  setColor(Qt::black);
40 
41  // Signals & slots
42  connect(m_popup, SIGNAL(selected(const QColor&)), this, SLOT(onPopupSelected(const QColor&)));
43 }
44 
46 
48 {
49  m_popup->setSelected(color);
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  if (!m_isOpen)
68  {
69  m_popup->move(mapToGlobal(QPoint(0, height())));
70  m_popup->show();
71  m_isOpen = true;
72  }
73  else
74  {
75  m_popup->close();
76  m_isOpen = false;
77  }
78 }
79 
81 {
82  QPixmap pix(iconSize());
83  pix.fill(m_selectedColor);
84  QPainter p(&pix);
85  p.setPen(QPen(Qt::darkGray, 2));
86  p.drawRect(pix.rect());
87  setIcon(pix);
88 }
89 
91 {
92  setColor(color);
93  emit colorChanged(color);
94  m_isOpen = false;
95 }
Create a frame with a default color palette.
te::gm::Polygon * p
Custom widget used to pick a color.