26 #ifndef __TERRALIB_QT_WIDGETS_UTILS_INTERNAL_COLORPICKERTOOLBUTTON_H
27 #define __TERRALIB_QT_WIDGETS_UTILS_INTERNAL_COLORPICKERTOOLBUTTON_H
30 #include "../Config.h"
33 #include <QApplication>
35 #include <QColorDialog>
37 #include <QGridLayout>
39 #include <QMouseEvent>
42 #include <QToolButton>
88 setWindowFlags(Qt::Popup);
89 setFrameShape(QFrame::StyledPanel);
90 setFrameShadow(QFrame::Plain);
91 setStyleSheet(
"QFrame{background-color: rgb(255, 255, 255);border-color: rgb(0, 0, 0);}");
95 for(
int g = 0; g < 4; ++g)
96 for(
int r = 0; r < 4; ++r)
97 for(
int b = 0; b < 3; ++b)
98 m_stdrgb[i++] = qRgb(r * 255 / 3, g * 255 / 3, b * 255 / 2);
101 int height = 48 /
COLS;
105 resize(width, height);
107 setMouseTracking(
true);
110 void paintButton(QPainter* painter,
const QRectF& rc,
const QString& text,
bool hover)
112 !hover ? painter->setBrush(Qt::lightGray) : painter->setBrush(Qt::gray);
113 painter->drawRect(rc);
114 painter->setPen(Qt::black);
115 painter->drawText(rc, text, Qt::AlignHCenter | Qt::AlignVCenter);
120 QPainter painter(
this);
122 painter.drawRect(0, 0, width() - 1, height() - 1);
123 painter.drawText(QRect(10, 1, this->width(), 19), tr(
"Basic Colors"), Qt::AlignLeft | Qt::AlignVCenter);
127 painter.setPen(Qt::darkGray);
128 for(
int i = 0; i < 48; ++i)
132 row = (int)(i /
COLS);
141 painter.setBrush(color);
142 painter.drawRect(rc);
146 QPointF mousePos = mapFromGlobal(QCursor::pos());
159 rc.setTop(rc.top() - 2);
160 rc.setLeft(rc.left() - 2);
161 rc.setBottom(rc.bottom() + 2);
162 rc.setRight(rc.right() + 2);
165 painter.drawRect(rc);
179 if(!rect().contains(e->pos()))
192 #if (QT_VERSION >= 0x050000)
199 QColor color = QColorDialog::getColor(
m_currentColor,
this,
"", QColorDialog::ShowAlphaChannel);
244 void setColor(
const QColor& color);
246 QColor getColor()
const;
250 void resizeEvent(QResizeEvent* e);
252 void mousePressEvent(QMouseEvent* e);
258 void onPopupSelected(
const QColor& color);
262 void colorChanged(
const QColor&);
275 #endif // __TERRALIB_QT_WIDGETS_UTILS_INTERNAL_COLORPICKERTOOLBUTTON_H