diff options
-rw-r--r-- | Preferences.cc | 59 | ||||
-rw-r--r-- | Preferences.h | 10 | ||||
-rw-r--r-- | Preferences.ui | 55 | ||||
-rw-r--r-- | mainwin.cc | 2 | ||||
-rw-r--r-- | openscad.pro | 2 | ||||
-rw-r--r-- | qtcolorbutton/README.txt | 2 | ||||
-rw-r--r-- | qtcolorbutton/qtcolorbutton.cpp | 278 | ||||
-rw-r--r-- | qtcolorbutton/qtcolorbutton.h | 86 | ||||
-rw-r--r-- | qtcolorbutton/qtcolorbutton.pri | 4 |
9 files changed, 472 insertions, 26 deletions
diff --git a/Preferences.cc b/Preferences.cc index f098ab4..1c7f988 100644 --- a/Preferences.cc +++ b/Preferences.cc @@ -26,16 +26,39 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent) { setupUi(this); - this->colormap[BACKGROUND_COLOR] = QColor(0xff, 0xff, 0xe5); - this->colormap[OPENCSG_FACE_FRONT_COLOR] = QColor(0xf9, 0xd7, 0x2c); - this->colormap[OPENCSG_FACE_BACK_COLOR] = QColor(0x9d, 0xcb, 0x51); - this->colormap[CGAL_FACE_FRONT_COLOR] = QColor(0xf9, 0xd7, 0x2c); - this->colormap[CGAL_FACE_BACK_COLOR] = QColor(0x9d, 0xcb, 0x51); - this->colormap[CGAL_FACE_2D_COLOR] = QColor(0x00, 0xbf, 0x99); - this->colormap[CGAL_EDGE_FRONT_COLOR] = QColor(0xff, 0x00, 0x00); - this->colormap[CGAL_EDGE_BACK_COLOR] = QColor(0xff, 0x00, 0x00); - this->colormap[CGAL_EDGE_2D_COLOR] = QColor(0xff, 0x00, 0x00); - this->colormap[CROSSHAIR_COLOR] = QColor(0x80, 0x00, 0x00); + this->colorscheme = this->colorSchemeChooser->item(0)->text(); + this->colorschemes["Cornfield"][BACKGROUND_COLOR] = QColor(0xff, 0xff, 0xe5); + this->colorschemes["Cornfield"][OPENCSG_FACE_FRONT_COLOR] = QColor(0xf9, 0xd7, 0x2c); + this->colorschemes["Cornfield"][OPENCSG_FACE_BACK_COLOR] = QColor(0x9d, 0xcb, 0x51); + this->colorschemes["Cornfield"][CGAL_FACE_FRONT_COLOR] = QColor(0xf9, 0xd7, 0x2c); + this->colorschemes["Cornfield"][CGAL_FACE_BACK_COLOR] = QColor(0x9d, 0xcb, 0x51); + this->colorschemes["Cornfield"][CGAL_FACE_2D_COLOR] = QColor(0x00, 0xbf, 0x99); + this->colorschemes["Cornfield"][CGAL_EDGE_FRONT_COLOR] = QColor(0xff, 0x00, 0x00); + this->colorschemes["Cornfield"][CGAL_EDGE_BACK_COLOR] = QColor(0xff, 0x00, 0x00); + this->colorschemes["Cornfield"][CGAL_EDGE_2D_COLOR] = QColor(0xff, 0x00, 0x00); + this->colorschemes["Cornfield"][CROSSHAIR_COLOR] = QColor(0x80, 0x00, 0x00); + + this->colorschemes["Metallic"][BACKGROUND_COLOR] = QColor(0xaa, 0xaa, 0xff); + this->colorschemes["Metallic"][OPENCSG_FACE_FRONT_COLOR] = QColor(0xdd, 0xdd, 0xff); + this->colorschemes["Metallic"][OPENCSG_FACE_BACK_COLOR] = QColor(0xdd, 0x22, 0xdd); + this->colorschemes["Metallic"][CGAL_FACE_FRONT_COLOR] = QColor(0xdd, 0xdd, 0xff); + this->colorschemes["Metallic"][CGAL_FACE_BACK_COLOR] = QColor(0xdd, 0x22, 0xdd); + this->colorschemes["Metallic"][CGAL_FACE_2D_COLOR] = QColor(0x00, 0xbf, 0x99); + this->colorschemes["Metallic"][CGAL_EDGE_FRONT_COLOR] = QColor(0xff, 0x00, 0x00); + this->colorschemes["Metallic"][CGAL_EDGE_BACK_COLOR] = QColor(0xff, 0x00, 0x00); + this->colorschemes["Metallic"][CGAL_EDGE_2D_COLOR] = QColor(0xff, 0x00, 0x00); + this->colorschemes["Metallic"][CROSSHAIR_COLOR] = QColor(0x80, 0x00, 0x00); + + this->colorschemes["Sunset"][BACKGROUND_COLOR] = QColor(0xaa, 0x44, 0x44); + this->colorschemes["Sunset"][OPENCSG_FACE_FRONT_COLOR] = QColor(0xff, 0xaa, 0xaa); + this->colorschemes["Sunset"][OPENCSG_FACE_BACK_COLOR] = QColor(0x88, 0x22, 0x33); + this->colorschemes["Sunset"][CGAL_FACE_FRONT_COLOR] = QColor(0xff, 0xaa, 0xaa); + this->colorschemes["Sunset"][CGAL_FACE_BACK_COLOR] = QColor(0x88, 0x22, 0x33); + this->colorschemes["Sunset"][CGAL_FACE_2D_COLOR] = QColor(0x00, 0xbf, 0x99); + this->colorschemes["Sunset"][CGAL_EDGE_FRONT_COLOR] = QColor(0xff, 0x00, 0x00); + this->colorschemes["Sunset"][CGAL_EDGE_BACK_COLOR] = QColor(0xff, 0x00, 0x00); + this->colorschemes["Sunset"][CGAL_EDGE_2D_COLOR] = QColor(0xff, 0x00, 0x00); + this->colorschemes["Sunset"][CROSSHAIR_COLOR] = QColor(0x80, 0x00, 0x00); QActionGroup *group = new QActionGroup(this); group->addAction(prefsAction3DView); @@ -44,6 +67,10 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent) prefsAction3DView->setChecked(true); this->actionTriggered(this->prefsAction3DView); + + connect(this->colorSchemeChooser, SIGNAL(itemSelectionChanged()), + this, SLOT(colorSchemeChanged())); + } Preferences::~Preferences() @@ -60,3 +87,15 @@ Preferences::actionTriggered(QAction *action) this->stackedWidget->setCurrentWidget(this->pageAdvanced); } } + +void Preferences::colorSchemeChanged() +{ + this->colorscheme = this->colorSchemeChooser->currentItem()->text(); + emit requestRedraw(); +} + +const QColor &Preferences::color(RenderColor idx) +{ + return this->colorschemes[this->colorscheme][idx]; +} + diff --git a/Preferences.h b/Preferences.h index 96ae4ca..9b8c816 100644 --- a/Preferences.h +++ b/Preferences.h @@ -24,15 +24,19 @@ public: CGAL_EDGE_2D_COLOR, CROSSHAIR_COLOR }; - void setColor(RenderColor idx, const QColor &color) { this->colormap[idx] = color; } - const QColor &color(RenderColor idx) { return this->colormap[idx]; } + const QColor &color(RenderColor idx); public slots: void actionTriggered(class QAction *); + void colorSchemeChanged(); + +signals: + void requestRedraw(); private: Preferences(QWidget *parent = NULL); - QMap<RenderColor, QColor> colormap; + QHash<QString, QMap<RenderColor, QColor> > colorschemes; + QString colorscheme; static Preferences *instance; }; diff --git a/Preferences.ui b/Preferences.ui index 3a2f127..1bfc80a 100644 --- a/Preferences.ui +++ b/Preferences.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>435</width> - <height>362</height> + <width>384</width> + <height>243</height> </rect> </property> <property name="windowTitle"> @@ -24,18 +24,44 @@ <number>0</number> </property> <widget class="QWidget" name="page3DView"> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <property name="margin"> - <number>0</number> - </property> + <layout class="QVBoxLayout" name="verticalLayout_4"> <item> - <layout class="QHBoxLayout" name="horizontalLayout"> + <layout class="QHBoxLayout" name="horizontalLayout" stretch="1,3"> <item> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Background color:</string> - </property> - </widget> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Color scheme:</string> + </property> + </widget> + </item> + <item> + <widget class="QListWidget" name="colorSchemeChooser"> + <property name="alternatingRowColors"> + <bool>false</bool> + </property> + <property name="currentRow"> + <number>0</number> + </property> + <item> + <property name="text"> + <string>Cornfield</string> + </property> + </item> + <item> + <property name="text"> + <string>Metallic</string> + </property> + </item> + <item> + <property name="text"> + <string>Sunset</string> + </property> + </item> + </widget> + </item> + </layout> </item> <item> <spacer name="horizontalSpacer"> @@ -60,7 +86,7 @@ <property name="sizeHint" stdset="0"> <size> <width>20</width> - <height>241</height> + <height>645</height> </size> </property> </spacer> @@ -102,6 +128,9 @@ </item> <item> <widget class="QLabel" name="label_2"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="text"> <string>advanced</string> </property> @@ -273,6 +273,8 @@ MainWindow::MainWindow(const char *filename) connect(editor->document(), SIGNAL(modificationChanged(bool)), fileActionSave, SLOT(setEnabled(bool))); connect(screen, SIGNAL(doAnimateUpdate()), this, SLOT(animateUpdate())); + connect(Preferences::inst(), SIGNAL(requestRedraw()), this->screen, SLOT(updateGL())); + // display this window and check for OpenGL 2.0 (OpenCSG) support viewModeThrownTogether(); show(); diff --git a/openscad.pro b/openscad.pro index 89338bc..d8b46cf 100644 --- a/openscad.pro +++ b/openscad.pro @@ -67,6 +67,8 @@ opencsg { } } +include(qtcolorbutton/qtcolorbutton.pri) + QMAKE_CXXFLAGS_RELEASE = -O3 -march=pentium QMAKE_CXXFLAGS_DEBUG = -O0 -ggdb diff --git a/qtcolorbutton/README.txt b/qtcolorbutton/README.txt new file mode 100644 index 0000000..4b55f67 --- /dev/null +++ b/qtcolorbutton/README.txt @@ -0,0 +1,2 @@ +The QtColorButton class is copied from the gradient editor in Qt's shared tool classes: +http://qt.gitorious.org/qt/qt/trees/master/tools/shared/qtgradienteditor diff --git a/qtcolorbutton/qtcolorbutton.cpp b/qtcolorbutton/qtcolorbutton.cpp new file mode 100644 index 0000000..21b9848 --- /dev/null +++ b/qtcolorbutton/qtcolorbutton.cpp @@ -0,0 +1,278 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtcolorbutton.h" +#include <QtGui/QColorDialog> +#include <QtGui/QPainter> +#include <QtCore/QMimeData> +#include <QtGui/QDragEnterEvent> +#include <QtGui/QApplication> + +QT_BEGIN_NAMESPACE + +class QtColorButtonPrivate +{ + QtColorButton *q_ptr; + Q_DECLARE_PUBLIC(QtColorButton) +public: + QColor m_color; +#ifndef QT_NO_DRAGANDDROP + QColor m_dragColor; + QPoint m_dragStart; + bool m_dragging; +#endif + bool m_backgroundCheckered; + + void slotEditColor(); + QColor shownColor() const; + QPixmap generatePixmap() const; +}; + +void QtColorButtonPrivate::slotEditColor() +{ + bool ok; + const QRgb rgba = QColorDialog::getRgba(m_color.rgba(), &ok, q_ptr); + if (!ok) + return; + const QColor c = QColor::fromRgba(rgba); + if (c == q_ptr->color()) + return; + q_ptr->setColor(c); + emit q_ptr->colorChanged(m_color); +} + +QColor QtColorButtonPrivate::shownColor() const +{ +#ifndef QT_NO_DRAGANDDROP + if (m_dragging) + return m_dragColor; +#endif + return m_color; +} + +QPixmap QtColorButtonPrivate::generatePixmap() const +{ + QPixmap pix(24, 24); + + int pixSize = 20; + QBrush br(shownColor()); + + QPixmap pm(2 * pixSize, 2 * pixSize); + QPainter pmp(&pm); + pmp.fillRect(0, 0, pixSize, pixSize, Qt::lightGray); + pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::lightGray); + pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::darkGray); + pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::darkGray); + pmp.fillRect(0, 0, 2 * pixSize, 2 * pixSize, shownColor()); + br = QBrush(pm); + + QPainter p(&pix); + int corr = 1; + QRect r = pix.rect().adjusted(corr, corr, -corr, -corr); + p.setBrushOrigin((r.width() % pixSize + pixSize) / 2 + corr, (r.height() % pixSize + pixSize) / 2 + corr); + p.fillRect(r, br); + + p.fillRect(r.width() / 4 + corr, r.height() / 4 + corr, + r.width() / 2, r.height() / 2, + QColor(shownColor().rgb())); + p.drawRect(pix.rect().adjusted(0, 0, -1, -1)); + + return pix; +} + +/////////////// + +QtColorButton::QtColorButton(QWidget *parent) + : QToolButton(parent) +{ + d_ptr = new QtColorButtonPrivate; + d_ptr->q_ptr = this; + d_ptr->m_dragging = false; + d_ptr->m_backgroundCheckered = true; + + setAcceptDrops(true); + + connect(this, SIGNAL(clicked()), this, SLOT(slotEditColor())); + setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); +} + +QtColorButton::~QtColorButton() +{ + delete d_ptr; +} + +void QtColorButton::setColor(const QColor &color) +{ + if (d_ptr->m_color == color) + return; + d_ptr->m_color = color; + update(); +} + +QColor QtColorButton::color() const +{ + return d_ptr->m_color; +} + +void QtColorButton::setBackgroundCheckered(bool checkered) +{ + if (d_ptr->m_backgroundCheckered == checkered) + return; + d_ptr->m_backgroundCheckered = checkered; + update(); +} + +bool QtColorButton::isBackgroundCheckered() const +{ + return d_ptr->m_backgroundCheckered; +} + +void QtColorButton::paintEvent(QPaintEvent *event) +{ + QToolButton::paintEvent(event); + if (!isEnabled()) + return; + + const int pixSize = 10; + QBrush br(d_ptr->shownColor()); + if (d_ptr->m_backgroundCheckered) { + QPixmap pm(2 * pixSize, 2 * pixSize); + QPainter pmp(&pm); + pmp.fillRect(0, 0, pixSize, pixSize, Qt::white); + pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::white); + pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::black); + pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::black); + pmp.fillRect(0, 0, 2 * pixSize, 2 * pixSize, d_ptr->shownColor()); + br = QBrush(pm); + } + + QPainter p(this); + const int corr = 4; + QRect r = rect().adjusted(corr, corr, -corr, -corr); + p.setBrushOrigin((r.width() % pixSize + pixSize) / 2 + corr, (r.height() % pixSize + pixSize) / 2 + corr); + p.fillRect(r, br); + + //const int adjX = qRound(r.width() / 4.0); + //const int adjY = qRound(r.height() / 4.0); + //p.fillRect(r.adjusted(adjX, adjY, -adjX, -adjY), + // QColor(d_ptr->shownColor().rgb())); + /* + p.fillRect(r.adjusted(0, r.height() * 3 / 4, 0, 0), + QColor(d_ptr->shownColor().rgb())); + p.fillRect(r.adjusted(0, 0, 0, -r.height() * 3 / 4), + QColor(d_ptr->shownColor().rgb())); + */ + /* + const QColor frameColor0(0, 0, 0, qRound(0.2 * (0xFF - d_ptr->shownColor().alpha()))); + p.setPen(frameColor0); + p.drawRect(r.adjusted(adjX, adjY, -adjX - 1, -adjY - 1)); + */ + + const QColor frameColor1(0, 0, 0, 26); + p.setPen(frameColor1); + p.drawRect(r.adjusted(1, 1, -2, -2)); + const QColor frameColor2(0, 0, 0, 51); + p.setPen(frameColor2); + p.drawRect(r.adjusted(0, 0, -1, -1)); +} + +void QtColorButton::mousePressEvent(QMouseEvent *event) +{ +#ifndef QT_NO_DRAGANDDROP + if (event->button() == Qt::LeftButton) + d_ptr->m_dragStart = event->pos(); +#endif + QToolButton::mousePressEvent(event); +} + +void QtColorButton::mouseMoveEvent(QMouseEvent *event) +{ +#ifndef QT_NO_DRAGANDDROP + if (event->buttons() & Qt::LeftButton && + (d_ptr->m_dragStart - event->pos()).manhattanLength() > QApplication::startDragDistance()) { + QMimeData *mime = new QMimeData; + mime->setColorData(color()); + QDrag *drg = new QDrag(this); + drg->setMimeData(mime); + drg->setPixmap(d_ptr->generatePixmap()); + setDown(false); + event->accept(); + drg->start(); + return; + } +#endif + QToolButton::mouseMoveEvent(event); +} + +#ifndef QT_NO_DRAGANDDROP +void QtColorButton::dragEnterEvent(QDragEnterEvent *event) +{ + const QMimeData *mime = event->mimeData(); + if (!mime->hasColor()) + return; + + event->accept(); + d_ptr->m_dragColor = qvariant_cast<QColor>(mime->colorData()); + d_ptr->m_dragging = true; + update(); +} + +void QtColorButton::dragLeaveEvent(QDragLeaveEvent *event) +{ + event->accept(); + d_ptr->m_dragging = false; + update(); +} + +void QtColorButton::dropEvent(QDropEvent *event) +{ + event->accept(); + d_ptr->m_dragging = false; + if (d_ptr->m_dragColor == color()) + return; + setColor(d_ptr->m_dragColor); + emit colorChanged(color()); +} +#endif + +QT_END_NAMESPACE + +#include "moc_qtcolorbutton.cpp" diff --git a/qtcolorbutton/qtcolorbutton.h b/qtcolorbutton/qtcolorbutton.h new file mode 100644 index 0000000..26bdde0 --- /dev/null +++ b/qtcolorbutton/qtcolorbutton.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTCOLORBUTTON_H +#define QTCOLORBUTTON_H + +#include <QtGui/QToolButton> + +QT_BEGIN_NAMESPACE + +class QtColorButton : public QToolButton +{ + Q_OBJECT + Q_PROPERTY(bool backgroundCheckered READ isBackgroundCheckered WRITE setBackgroundCheckered) +public: + QtColorButton(QWidget *parent = 0); + ~QtColorButton(); + + bool isBackgroundCheckered() const; + void setBackgroundCheckered(bool checkered); + + QColor color() const; + +public slots: + + void setColor(const QColor &color); + +signals: + void colorChanged(const QColor &color); +protected: + void paintEvent(QPaintEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); +#ifndef QT_NO_DRAGANDDROP + void dragEnterEvent(QDragEnterEvent *event); + void dragLeaveEvent(QDragLeaveEvent *event); + void dropEvent(QDropEvent *event); +#endif +private: + class QtColorButtonPrivate *d_ptr; + Q_DECLARE_PRIVATE(QtColorButton) + Q_DISABLE_COPY(QtColorButton) + Q_PRIVATE_SLOT(d_func(), void slotEditColor()) +}; + +QT_END_NAMESPACE + +#endif diff --git a/qtcolorbutton/qtcolorbutton.pri b/qtcolorbutton/qtcolorbutton.pri new file mode 100644 index 0000000..0e41068 --- /dev/null +++ b/qtcolorbutton/qtcolorbutton.pri @@ -0,0 +1,4 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD +SOURCES += $$PWD/qtcolorbutton.cpp +HEADERS += $$PWD/qtcolorbutton.h |