blob: 735f23fd6045be7b5583b0ac92320a827eba4c97 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2008 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "btcolorwidget.h"
#include <QPalette>
#include <QColor>
#include <QMouseEvent>
#include <QColorDialog>
BtColorWidget::BtColorWidget(QWidget* parent)
: QFrame(parent) {
setFrameShadow(QFrame::Sunken);
setFrameShape(QFrame::StyledPanel);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
setAutoFillBackground(true);
}
BtColorWidget::~BtColorWidget() {
}
QSize BtColorWidget::sizeHint() const {
return QSize(35, 18);
}
void BtColorWidget::setColor(const QColor& color) {
QPalette p = palette();
p.setColor(QPalette::Normal, QPalette::Window, color);
setPalette(p);
if (color.isValid())
m_color = color;
else
m_color = QColor(0, 0, 0);
update();
}
void BtColorWidget::mouseReleaseEvent(QMouseEvent* event) {
if (event->button() == Qt::LeftButton) {
event->accept();
showColorDialog();
return;
}
}
void BtColorWidget::showColorDialog() {
QColor color = QColorDialog::getColor(m_color, this);
if (color.isValid()) {
m_color = color;
emit changed(m_color);
}
}
|