diff options
Diffstat (limited to 'src/frontend/display/btcolorwidget.cpp')
-rw-r--r-- | src/frontend/display/btcolorwidget.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/frontend/display/btcolorwidget.cpp b/src/frontend/display/btcolorwidget.cpp new file mode 100644 index 0000000..f807b05 --- /dev/null +++ b/src/frontend/display/btcolorwidget.cpp @@ -0,0 +1,65 @@ +/********* +* +* 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); + } +} |