| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the demonstration applications of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "colorswatch.h"
|
|---|
| 43 |
|
|---|
| 44 | #include <QAction>
|
|---|
| 45 | #include <QtEvents>
|
|---|
| 46 | #include <QFrame>
|
|---|
| 47 | #include <QMainWindow>
|
|---|
| 48 | #include <QMenu>
|
|---|
| 49 | #include <QPainter>
|
|---|
| 50 | #include <QImage>
|
|---|
| 51 | #include <QColor>
|
|---|
| 52 | #include <QDialog>
|
|---|
| 53 | #include <QGridLayout>
|
|---|
| 54 | #include <QSpinBox>
|
|---|
| 55 | #include <QLabel>
|
|---|
| 56 | #include <QPainterPath>
|
|---|
| 57 | #include <QPushButton>
|
|---|
| 58 | #include <QHBoxLayout>
|
|---|
| 59 | #include <QBitmap>
|
|---|
| 60 | #include <QtDebug>
|
|---|
| 61 |
|
|---|
| 62 | #undef DEBUG_SIZEHINTS
|
|---|
| 63 |
|
|---|
| 64 | QColor bgColorForName(const QString &name)
|
|---|
| 65 | {
|
|---|
| 66 | if (name == "Black")
|
|---|
| 67 | return QColor("#D8D8D8");
|
|---|
| 68 | else if (name == "White")
|
|---|
| 69 | return QColor("#F1F1F1");
|
|---|
| 70 | else if (name == "Red")
|
|---|
| 71 | return QColor("#F1D8D8");
|
|---|
| 72 | else if (name == "Green")
|
|---|
| 73 | return QColor("#D8E4D8");
|
|---|
| 74 | else if (name == "Blue")
|
|---|
| 75 | return QColor("#D8D8F1");
|
|---|
| 76 | else if (name == "Yellow")
|
|---|
| 77 | return QColor("#F1F0D8");
|
|---|
| 78 | return QColor(name).light(110);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | QColor fgColorForName(const QString &name)
|
|---|
| 82 | {
|
|---|
| 83 | if (name == "Black")
|
|---|
| 84 | return QColor("#6C6C6C");
|
|---|
| 85 | else if (name == "White")
|
|---|
| 86 | return QColor("#F8F8F8");
|
|---|
| 87 | else if (name == "Red")
|
|---|
| 88 | return QColor("#F86C6C");
|
|---|
| 89 | else if (name == "Green")
|
|---|
| 90 | return QColor("#6CB26C");
|
|---|
| 91 | else if (name == "Blue")
|
|---|
| 92 | return QColor("#6C6CF8");
|
|---|
| 93 | else if (name == "Yellow")
|
|---|
| 94 | return QColor("#F8F76C");
|
|---|
| 95 | return QColor(name);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | class ColorDock : public QFrame
|
|---|
| 99 | {
|
|---|
| 100 | Q_OBJECT
|
|---|
| 101 | public:
|
|---|
| 102 | ColorDock(const QString &c, QWidget *parent);
|
|---|
| 103 |
|
|---|
| 104 | virtual QSize sizeHint() const;
|
|---|
| 105 | virtual QSize minimumSizeHint() const;
|
|---|
| 106 |
|
|---|
| 107 | void setCustomSizeHint(const QSize &size);
|
|---|
| 108 |
|
|---|
| 109 | public slots:
|
|---|
| 110 | void changeSizeHints();
|
|---|
| 111 |
|
|---|
| 112 | protected:
|
|---|
| 113 | void paintEvent(QPaintEvent *);
|
|---|
| 114 | QString color;
|
|---|
| 115 | QSize szHint, minSzHint;
|
|---|
| 116 | };
|
|---|
| 117 |
|
|---|
| 118 | ColorDock::ColorDock(const QString &c, QWidget *parent)
|
|---|
| 119 | : QFrame(parent) , color(c)
|
|---|
| 120 | {
|
|---|
| 121 | QFont font = this->font();
|
|---|
| 122 | font.setPointSize(8);
|
|---|
| 123 | setFont(font);
|
|---|
| 124 | szHint = QSize(-1, -1);
|
|---|
| 125 | minSzHint = QSize(125, 75);
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | QSize ColorDock::sizeHint() const
|
|---|
| 129 | {
|
|---|
| 130 | return szHint;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | QSize ColorDock::minimumSizeHint() const
|
|---|
| 134 | {
|
|---|
| 135 | return minSzHint;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | void ColorDock::paintEvent(QPaintEvent *)
|
|---|
| 139 | {
|
|---|
| 140 | QPainter p(this);
|
|---|
| 141 | p.setRenderHint(QPainter::Antialiasing);
|
|---|
| 142 | p.fillRect(rect(), bgColorForName(color));
|
|---|
| 143 |
|
|---|
| 144 | p.save();
|
|---|
| 145 |
|
|---|
| 146 | extern void render_qt_text(QPainter *, int, int, const QColor &);
|
|---|
| 147 | render_qt_text(&p, width(), height(), fgColorForName(color));
|
|---|
| 148 |
|
|---|
| 149 | p.restore();
|
|---|
| 150 |
|
|---|
| 151 | #ifdef DEBUG_SIZEHINTS
|
|---|
| 152 | p.setRenderHint(QPainter::Antialiasing, false);
|
|---|
| 153 |
|
|---|
| 154 | QSize sz = size();
|
|---|
| 155 | QSize szHint = sizeHint();
|
|---|
| 156 | QSize minSzHint = minimumSizeHint();
|
|---|
| 157 | QSize maxSz = maximumSize();
|
|---|
| 158 | QString text = QString::fromLatin1("sz: %1x%2\nszHint: %3x%4\nminSzHint: %5x%6\n"
|
|---|
| 159 | "maxSz: %8x%9")
|
|---|
| 160 | .arg(sz.width()).arg(sz.height())
|
|---|
| 161 | .arg(szHint.width()).arg(szHint.height())
|
|---|
| 162 | .arg(minSzHint.width()).arg(minSzHint.height())
|
|---|
| 163 | .arg(maxSz.width()).arg(maxSz.height());
|
|---|
| 164 |
|
|---|
| 165 | QRect r = fontMetrics().boundingRect(rect(), Qt::AlignLeft|Qt::AlignTop, text);
|
|---|
| 166 | r.adjust(-2, -2, 1, 1);
|
|---|
| 167 | p.translate(4, 4);
|
|---|
| 168 | QColor bg = Qt::yellow;
|
|---|
| 169 | bg.setAlpha(120);
|
|---|
| 170 | p.setBrush(bg);
|
|---|
| 171 | p.setPen(Qt::black);
|
|---|
| 172 | p.drawRect(r);
|
|---|
| 173 | p.drawText(rect(), Qt::AlignLeft|Qt::AlignTop, text);
|
|---|
| 174 | #endif // DEBUG_SIZEHINTS
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | static QSpinBox *createSpinBox(int value, QWidget *parent, int max = 1000)
|
|---|
| 178 | {
|
|---|
| 179 | QSpinBox *result = new QSpinBox(parent);
|
|---|
| 180 | result->setMinimum(-1);
|
|---|
| 181 | result->setMaximum(max);
|
|---|
| 182 | result->setValue(value);
|
|---|
| 183 | return result;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | void ColorDock::changeSizeHints()
|
|---|
| 187 | {
|
|---|
| 188 | QDialog dialog(this);
|
|---|
| 189 | dialog.setWindowTitle(color);
|
|---|
| 190 |
|
|---|
| 191 | QVBoxLayout *topLayout = new QVBoxLayout(&dialog);
|
|---|
| 192 |
|
|---|
| 193 | QGridLayout *inputLayout = new QGridLayout();
|
|---|
| 194 | topLayout->addLayout(inputLayout);
|
|---|
| 195 |
|
|---|
| 196 | inputLayout->addWidget(new QLabel(tr("Size Hint:"), &dialog), 0, 0);
|
|---|
| 197 | inputLayout->addWidget(new QLabel(tr("Min Size Hint:"), &dialog), 1, 0);
|
|---|
| 198 | inputLayout->addWidget(new QLabel(tr("Max Size:"), &dialog), 2, 0);
|
|---|
| 199 | inputLayout->addWidget(new QLabel(tr("Dockwgt Max Size:"), &dialog), 3, 0);
|
|---|
| 200 |
|
|---|
| 201 | QSpinBox *szHintW = createSpinBox(szHint.width(), &dialog);
|
|---|
| 202 | inputLayout->addWidget(szHintW, 0, 1);
|
|---|
| 203 | QSpinBox *szHintH = createSpinBox(szHint.height(), &dialog);
|
|---|
| 204 | inputLayout->addWidget(szHintH, 0, 2);
|
|---|
| 205 |
|
|---|
| 206 | QSpinBox *minSzHintW = createSpinBox(minSzHint.width(), &dialog);
|
|---|
| 207 | inputLayout->addWidget(minSzHintW, 1, 1);
|
|---|
| 208 | QSpinBox *minSzHintH = createSpinBox(minSzHint.height(), &dialog);
|
|---|
| 209 | inputLayout->addWidget(minSzHintH, 1, 2);
|
|---|
| 210 |
|
|---|
| 211 | QSize maxSz = maximumSize();
|
|---|
| 212 | QSpinBox *maxSzW = createSpinBox(maxSz.width(), &dialog, QWIDGETSIZE_MAX);
|
|---|
| 213 | inputLayout->addWidget(maxSzW, 2, 1);
|
|---|
| 214 | QSpinBox *maxSzH = createSpinBox(maxSz.height(), &dialog, QWIDGETSIZE_MAX);
|
|---|
| 215 | inputLayout->addWidget(maxSzH, 2, 2);
|
|---|
| 216 |
|
|---|
| 217 | QSize dwMaxSz = parentWidget()->maximumSize();
|
|---|
| 218 | QSpinBox *dwMaxSzW = createSpinBox(dwMaxSz.width(), &dialog, QWIDGETSIZE_MAX);
|
|---|
| 219 | inputLayout->addWidget(dwMaxSzW, 3, 1);
|
|---|
| 220 | QSpinBox *dwMaxSzH = createSpinBox(dwMaxSz.height(), &dialog, QWIDGETSIZE_MAX);
|
|---|
| 221 | inputLayout->addWidget(dwMaxSzH, 3, 2);
|
|---|
| 222 |
|
|---|
| 223 | inputLayout->setColumnStretch(1, 1);
|
|---|
| 224 | inputLayout->setColumnStretch(2, 1);
|
|---|
| 225 |
|
|---|
| 226 | topLayout->addStretch();
|
|---|
| 227 |
|
|---|
| 228 | QHBoxLayout *buttonBox = new QHBoxLayout();
|
|---|
| 229 | topLayout->addLayout(buttonBox);
|
|---|
| 230 |
|
|---|
| 231 | QPushButton *okButton = new QPushButton(tr("Ok"), &dialog);
|
|---|
| 232 | QPushButton *cancelButton = new QPushButton(tr("Cancel"), &dialog);
|
|---|
| 233 | connect(okButton, SIGNAL(clicked()), &dialog, SLOT(accept()));
|
|---|
| 234 | connect(cancelButton, SIGNAL(clicked()), &dialog, SLOT(reject()));
|
|---|
| 235 | buttonBox->addStretch();
|
|---|
| 236 | buttonBox->addWidget(cancelButton);
|
|---|
| 237 | buttonBox->addWidget(okButton);
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 | if (!dialog.exec())
|
|---|
| 241 | return;
|
|---|
| 242 |
|
|---|
| 243 | szHint = QSize(szHintW->value(), szHintH->value());
|
|---|
| 244 | minSzHint = QSize(minSzHintW->value(), minSzHintH->value());
|
|---|
| 245 | maxSz = QSize(maxSzW->value(), maxSzH->value());
|
|---|
| 246 | setMaximumSize(maxSz);
|
|---|
| 247 | dwMaxSz = QSize(dwMaxSzW->value(), dwMaxSzH->value());
|
|---|
| 248 | parentWidget()->setMaximumSize(dwMaxSz);
|
|---|
| 249 | updateGeometry();
|
|---|
| 250 | update();
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | void ColorDock::setCustomSizeHint(const QSize &size)
|
|---|
| 254 | {
|
|---|
| 255 | szHint = size;
|
|---|
| 256 | updateGeometry();
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | ColorSwatch::ColorSwatch(const QString &colorName, QWidget *parent, Qt::WindowFlags flags)
|
|---|
| 260 | : QDockWidget(parent, flags)
|
|---|
| 261 | {
|
|---|
| 262 | setObjectName(colorName + QLatin1String(" Dock Widget"));
|
|---|
| 263 | setWindowTitle(objectName() + QLatin1String(" [*]"));
|
|---|
| 264 |
|
|---|
| 265 | QFrame *swatch = new ColorDock(colorName, this);
|
|---|
| 266 | swatch->setFrameStyle(QFrame::Box | QFrame::Sunken);
|
|---|
| 267 |
|
|---|
| 268 | setWidget(swatch);
|
|---|
| 269 |
|
|---|
| 270 | changeSizeHintsAction = new QAction(tr("Change Size Hints"), this);
|
|---|
| 271 | connect(changeSizeHintsAction, SIGNAL(triggered()), swatch, SLOT(changeSizeHints()));
|
|---|
| 272 |
|
|---|
| 273 | closableAction = new QAction(tr("Closable"), this);
|
|---|
| 274 | closableAction->setCheckable(true);
|
|---|
| 275 | connect(closableAction, SIGNAL(triggered(bool)), SLOT(changeClosable(bool)));
|
|---|
| 276 |
|
|---|
| 277 | movableAction = new QAction(tr("Movable"), this);
|
|---|
| 278 | movableAction->setCheckable(true);
|
|---|
| 279 | connect(movableAction, SIGNAL(triggered(bool)), SLOT(changeMovable(bool)));
|
|---|
| 280 |
|
|---|
| 281 | floatableAction = new QAction(tr("Floatable"), this);
|
|---|
| 282 | floatableAction->setCheckable(true);
|
|---|
| 283 | connect(floatableAction, SIGNAL(triggered(bool)), SLOT(changeFloatable(bool)));
|
|---|
| 284 |
|
|---|
| 285 | verticalTitleBarAction = new QAction(tr("Vertical title bar"), this);
|
|---|
| 286 | verticalTitleBarAction->setCheckable(true);
|
|---|
| 287 | connect(verticalTitleBarAction, SIGNAL(triggered(bool)),
|
|---|
| 288 | SLOT(changeVerticalTitleBar(bool)));
|
|---|
| 289 |
|
|---|
| 290 | floatingAction = new QAction(tr("Floating"), this);
|
|---|
| 291 | floatingAction->setCheckable(true);
|
|---|
| 292 | connect(floatingAction, SIGNAL(triggered(bool)), SLOT(changeFloating(bool)));
|
|---|
| 293 |
|
|---|
| 294 | allowedAreasActions = new QActionGroup(this);
|
|---|
| 295 | allowedAreasActions->setExclusive(false);
|
|---|
| 296 |
|
|---|
| 297 | allowLeftAction = new QAction(tr("Allow on Left"), this);
|
|---|
| 298 | allowLeftAction->setCheckable(true);
|
|---|
| 299 | connect(allowLeftAction, SIGNAL(triggered(bool)), SLOT(allowLeft(bool)));
|
|---|
| 300 |
|
|---|
| 301 | allowRightAction = new QAction(tr("Allow on Right"), this);
|
|---|
| 302 | allowRightAction->setCheckable(true);
|
|---|
| 303 | connect(allowRightAction, SIGNAL(triggered(bool)), SLOT(allowRight(bool)));
|
|---|
| 304 |
|
|---|
| 305 | allowTopAction = new QAction(tr("Allow on Top"), this);
|
|---|
| 306 | allowTopAction->setCheckable(true);
|
|---|
| 307 | connect(allowTopAction, SIGNAL(triggered(bool)), SLOT(allowTop(bool)));
|
|---|
| 308 |
|
|---|
| 309 | allowBottomAction = new QAction(tr("Allow on Bottom"), this);
|
|---|
| 310 | allowBottomAction->setCheckable(true);
|
|---|
| 311 | connect(allowBottomAction, SIGNAL(triggered(bool)), SLOT(allowBottom(bool)));
|
|---|
| 312 |
|
|---|
| 313 | allowedAreasActions->addAction(allowLeftAction);
|
|---|
| 314 | allowedAreasActions->addAction(allowRightAction);
|
|---|
| 315 | allowedAreasActions->addAction(allowTopAction);
|
|---|
| 316 | allowedAreasActions->addAction(allowBottomAction);
|
|---|
| 317 |
|
|---|
| 318 | areaActions = new QActionGroup(this);
|
|---|
| 319 | areaActions->setExclusive(true);
|
|---|
| 320 |
|
|---|
| 321 | leftAction = new QAction(tr("Place on Left") , this);
|
|---|
| 322 | leftAction->setCheckable(true);
|
|---|
| 323 | connect(leftAction, SIGNAL(triggered(bool)), SLOT(placeLeft(bool)));
|
|---|
| 324 |
|
|---|
| 325 | rightAction = new QAction(tr("Place on Right") , this);
|
|---|
| 326 | rightAction->setCheckable(true);
|
|---|
| 327 | connect(rightAction, SIGNAL(triggered(bool)), SLOT(placeRight(bool)));
|
|---|
| 328 |
|
|---|
| 329 | topAction = new QAction(tr("Place on Top") , this);
|
|---|
| 330 | topAction->setCheckable(true);
|
|---|
| 331 | connect(topAction, SIGNAL(triggered(bool)), SLOT(placeTop(bool)));
|
|---|
| 332 |
|
|---|
| 333 | bottomAction = new QAction(tr("Place on Bottom") , this);
|
|---|
| 334 | bottomAction->setCheckable(true);
|
|---|
| 335 | connect(bottomAction, SIGNAL(triggered(bool)), SLOT(placeBottom(bool)));
|
|---|
| 336 |
|
|---|
| 337 | areaActions->addAction(leftAction);
|
|---|
| 338 | areaActions->addAction(rightAction);
|
|---|
| 339 | areaActions->addAction(topAction);
|
|---|
| 340 | areaActions->addAction(bottomAction);
|
|---|
| 341 |
|
|---|
| 342 | connect(movableAction, SIGNAL(triggered(bool)), areaActions, SLOT(setEnabled(bool)));
|
|---|
| 343 |
|
|---|
| 344 | connect(movableAction, SIGNAL(triggered(bool)), allowedAreasActions, SLOT(setEnabled(bool)));
|
|---|
| 345 |
|
|---|
| 346 | connect(floatableAction, SIGNAL(triggered(bool)), floatingAction, SLOT(setEnabled(bool)));
|
|---|
| 347 |
|
|---|
| 348 | connect(floatingAction, SIGNAL(triggered(bool)), floatableAction, SLOT(setDisabled(bool)));
|
|---|
| 349 | connect(movableAction, SIGNAL(triggered(bool)), floatableAction, SLOT(setEnabled(bool)));
|
|---|
| 350 |
|
|---|
| 351 | tabMenu = new QMenu(this);
|
|---|
| 352 | tabMenu->setTitle(tr("Tab into"));
|
|---|
| 353 | connect(tabMenu, SIGNAL(triggered(QAction*)), this, SLOT(tabInto(QAction*)));
|
|---|
| 354 |
|
|---|
| 355 | splitHMenu = new QMenu(this);
|
|---|
| 356 | splitHMenu->setTitle(tr("Split horizontally into"));
|
|---|
| 357 | connect(splitHMenu, SIGNAL(triggered(QAction*)), this, SLOT(splitInto(QAction*)));
|
|---|
| 358 |
|
|---|
| 359 | splitVMenu = new QMenu(this);
|
|---|
| 360 | splitVMenu->setTitle(tr("Split vertically into"));
|
|---|
| 361 | connect(splitVMenu, SIGNAL(triggered(QAction*)), this, SLOT(splitInto(QAction*)));
|
|---|
| 362 |
|
|---|
| 363 | windowModifiedAction = new QAction(tr("Modified"), this);
|
|---|
| 364 | windowModifiedAction->setCheckable(true);
|
|---|
| 365 | windowModifiedAction->setChecked(false);
|
|---|
| 366 | connect(windowModifiedAction, SIGNAL(toggled(bool)), this, SLOT(setWindowModified(bool)));
|
|---|
| 367 |
|
|---|
| 368 | menu = new QMenu(colorName, this);
|
|---|
| 369 | menu->addAction(toggleViewAction());
|
|---|
| 370 | QAction *action = menu->addAction(tr("Raise"));
|
|---|
| 371 | connect(action, SIGNAL(triggered()), this, SLOT(raise()));
|
|---|
| 372 | menu->addAction(changeSizeHintsAction);
|
|---|
| 373 | menu->addSeparator();
|
|---|
| 374 | menu->addAction(closableAction);
|
|---|
| 375 | menu->addAction(movableAction);
|
|---|
| 376 | menu->addAction(floatableAction);
|
|---|
| 377 | menu->addAction(floatingAction);
|
|---|
| 378 | menu->addAction(verticalTitleBarAction);
|
|---|
| 379 | menu->addSeparator();
|
|---|
| 380 | menu->addActions(allowedAreasActions->actions());
|
|---|
| 381 | menu->addSeparator();
|
|---|
| 382 | menu->addActions(areaActions->actions());
|
|---|
| 383 | menu->addSeparator();
|
|---|
| 384 | menu->addMenu(splitHMenu);
|
|---|
| 385 | menu->addMenu(splitVMenu);
|
|---|
| 386 | menu->addMenu(tabMenu);
|
|---|
| 387 | menu->addSeparator();
|
|---|
| 388 | menu->addAction(windowModifiedAction);
|
|---|
| 389 |
|
|---|
| 390 | connect(menu, SIGNAL(aboutToShow()), this, SLOT(updateContextMenu()));
|
|---|
| 391 |
|
|---|
| 392 | if(colorName == "Black") {
|
|---|
| 393 | leftAction->setShortcut(Qt::CTRL|Qt::Key_W);
|
|---|
| 394 | rightAction->setShortcut(Qt::CTRL|Qt::Key_E);
|
|---|
| 395 | toggleViewAction()->setShortcut(Qt::CTRL|Qt::Key_R);
|
|---|
| 396 | }
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | void ColorSwatch::updateContextMenu()
|
|---|
| 400 | {
|
|---|
| 401 | QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
|
|---|
| 402 | const Qt::DockWidgetArea area = mainWindow->dockWidgetArea(this);
|
|---|
| 403 | const Qt::DockWidgetAreas areas = allowedAreas();
|
|---|
| 404 |
|
|---|
| 405 | closableAction->setChecked(features() & QDockWidget::DockWidgetClosable);
|
|---|
| 406 | if (windowType() == Qt::Drawer) {
|
|---|
| 407 | floatableAction->setEnabled(false);
|
|---|
| 408 | floatingAction->setEnabled(false);
|
|---|
| 409 | movableAction->setEnabled(false);
|
|---|
| 410 | verticalTitleBarAction->setChecked(false);
|
|---|
| 411 | } else {
|
|---|
| 412 | floatableAction->setChecked(features() & QDockWidget::DockWidgetFloatable);
|
|---|
| 413 | floatingAction->setChecked(isWindow());
|
|---|
| 414 | // done after floating, to get 'floatable' correctly initialized
|
|---|
| 415 | movableAction->setChecked(features() & QDockWidget::DockWidgetMovable);
|
|---|
| 416 | verticalTitleBarAction
|
|---|
| 417 | ->setChecked(features() & QDockWidget::DockWidgetVerticalTitleBar);
|
|---|
| 418 | }
|
|---|
| 419 |
|
|---|
| 420 | allowLeftAction->setChecked(isAreaAllowed(Qt::LeftDockWidgetArea));
|
|---|
| 421 | allowRightAction->setChecked(isAreaAllowed(Qt::RightDockWidgetArea));
|
|---|
| 422 | allowTopAction->setChecked(isAreaAllowed(Qt::TopDockWidgetArea));
|
|---|
| 423 | allowBottomAction->setChecked(isAreaAllowed(Qt::BottomDockWidgetArea));
|
|---|
| 424 |
|
|---|
| 425 | if (allowedAreasActions->isEnabled()) {
|
|---|
| 426 | allowLeftAction->setEnabled(area != Qt::LeftDockWidgetArea);
|
|---|
| 427 | allowRightAction->setEnabled(area != Qt::RightDockWidgetArea);
|
|---|
| 428 | allowTopAction->setEnabled(area != Qt::TopDockWidgetArea);
|
|---|
| 429 | allowBottomAction->setEnabled(area != Qt::BottomDockWidgetArea);
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 | leftAction->blockSignals(true);
|
|---|
| 433 | rightAction->blockSignals(true);
|
|---|
| 434 | topAction->blockSignals(true);
|
|---|
| 435 | bottomAction->blockSignals(true);
|
|---|
| 436 |
|
|---|
| 437 | leftAction->setChecked(area == Qt::LeftDockWidgetArea);
|
|---|
| 438 | rightAction->setChecked(area == Qt::RightDockWidgetArea);
|
|---|
| 439 | topAction->setChecked(area == Qt::TopDockWidgetArea);
|
|---|
| 440 | bottomAction->setChecked(area == Qt::BottomDockWidgetArea);
|
|---|
| 441 |
|
|---|
| 442 | leftAction->blockSignals(false);
|
|---|
| 443 | rightAction->blockSignals(false);
|
|---|
| 444 | topAction->blockSignals(false);
|
|---|
| 445 | bottomAction->blockSignals(false);
|
|---|
| 446 |
|
|---|
| 447 | if (areaActions->isEnabled()) {
|
|---|
| 448 | leftAction->setEnabled(areas & Qt::LeftDockWidgetArea);
|
|---|
| 449 | rightAction->setEnabled(areas & Qt::RightDockWidgetArea);
|
|---|
| 450 | topAction->setEnabled(areas & Qt::TopDockWidgetArea);
|
|---|
| 451 | bottomAction->setEnabled(areas & Qt::BottomDockWidgetArea);
|
|---|
| 452 | }
|
|---|
| 453 |
|
|---|
| 454 | tabMenu->clear();
|
|---|
| 455 | splitHMenu->clear();
|
|---|
| 456 | splitVMenu->clear();
|
|---|
| 457 | QList<ColorSwatch*> dock_list = qFindChildren<ColorSwatch*>(mainWindow);
|
|---|
| 458 | foreach (ColorSwatch *dock, dock_list) {
|
|---|
| 459 | // if (!dock->isVisible() || dock->isFloating())
|
|---|
| 460 | // continue;
|
|---|
| 461 | tabMenu->addAction(dock->objectName());
|
|---|
| 462 | splitHMenu->addAction(dock->objectName());
|
|---|
| 463 | splitVMenu->addAction(dock->objectName());
|
|---|
| 464 | }
|
|---|
| 465 | }
|
|---|
| 466 |
|
|---|
| 467 | void ColorSwatch::splitInto(QAction *action)
|
|---|
| 468 | {
|
|---|
| 469 | QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
|
|---|
| 470 | QList<ColorSwatch*> dock_list = qFindChildren<ColorSwatch*>(mainWindow);
|
|---|
| 471 | ColorSwatch *target = 0;
|
|---|
| 472 | foreach (ColorSwatch *dock, dock_list) {
|
|---|
| 473 | if (action->text() == dock->objectName()) {
|
|---|
| 474 | target = dock;
|
|---|
| 475 | break;
|
|---|
| 476 | }
|
|---|
| 477 | }
|
|---|
| 478 | if (target == 0)
|
|---|
| 479 | return;
|
|---|
| 480 |
|
|---|
| 481 | Qt::Orientation o = action->parent() == splitHMenu
|
|---|
| 482 | ? Qt::Horizontal : Qt::Vertical;
|
|---|
| 483 | mainWindow->splitDockWidget(target, this, o);
|
|---|
| 484 | }
|
|---|
| 485 |
|
|---|
| 486 | void ColorSwatch::tabInto(QAction *action)
|
|---|
| 487 | {
|
|---|
| 488 | QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
|
|---|
| 489 | QList<ColorSwatch*> dock_list = qFindChildren<ColorSwatch*>(mainWindow);
|
|---|
| 490 | ColorSwatch *target = 0;
|
|---|
| 491 | foreach (ColorSwatch *dock, dock_list) {
|
|---|
| 492 | if (action->text() == dock->objectName()) {
|
|---|
| 493 | target = dock;
|
|---|
| 494 | break;
|
|---|
| 495 | }
|
|---|
| 496 | }
|
|---|
| 497 | if (target == 0)
|
|---|
| 498 | return;
|
|---|
| 499 |
|
|---|
| 500 | mainWindow->tabifyDockWidget(target, this);
|
|---|
| 501 | }
|
|---|
| 502 |
|
|---|
| 503 | void ColorSwatch::contextMenuEvent(QContextMenuEvent *event)
|
|---|
| 504 | {
|
|---|
| 505 | event->accept();
|
|---|
| 506 | menu->exec(event->globalPos());
|
|---|
| 507 | }
|
|---|
| 508 |
|
|---|
| 509 | void ColorSwatch::resizeEvent(QResizeEvent *e)
|
|---|
| 510 | {
|
|---|
| 511 | if (BlueTitleBar *btb = qobject_cast<BlueTitleBar*>(titleBarWidget()))
|
|---|
| 512 | btb->updateMask();
|
|---|
| 513 |
|
|---|
| 514 | QDockWidget::resizeEvent(e);
|
|---|
| 515 | }
|
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 | void ColorSwatch::allow(Qt::DockWidgetArea area, bool a)
|
|---|
| 519 | {
|
|---|
| 520 | Qt::DockWidgetAreas areas = allowedAreas();
|
|---|
| 521 | areas = a ? areas | area : areas & ~area;
|
|---|
| 522 | setAllowedAreas(areas);
|
|---|
| 523 |
|
|---|
| 524 | if (areaActions->isEnabled()) {
|
|---|
| 525 | leftAction->setEnabled(areas & Qt::LeftDockWidgetArea);
|
|---|
| 526 | rightAction->setEnabled(areas & Qt::RightDockWidgetArea);
|
|---|
| 527 | topAction->setEnabled(areas & Qt::TopDockWidgetArea);
|
|---|
| 528 | bottomAction->setEnabled(areas & Qt::BottomDockWidgetArea);
|
|---|
| 529 | }
|
|---|
| 530 | }
|
|---|
| 531 |
|
|---|
| 532 | void ColorSwatch::place(Qt::DockWidgetArea area, bool p)
|
|---|
| 533 | {
|
|---|
| 534 | if (!p) return;
|
|---|
| 535 |
|
|---|
| 536 | QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
|
|---|
| 537 | mainWindow->addDockWidget(area, this);
|
|---|
| 538 |
|
|---|
| 539 | if (allowedAreasActions->isEnabled()) {
|
|---|
| 540 | allowLeftAction->setEnabled(area != Qt::LeftDockWidgetArea);
|
|---|
| 541 | allowRightAction->setEnabled(area != Qt::RightDockWidgetArea);
|
|---|
| 542 | allowTopAction->setEnabled(area != Qt::TopDockWidgetArea);
|
|---|
| 543 | allowBottomAction->setEnabled(area != Qt::BottomDockWidgetArea);
|
|---|
| 544 | }
|
|---|
| 545 | }
|
|---|
| 546 |
|
|---|
| 547 | void ColorSwatch::setCustomSizeHint(const QSize &size)
|
|---|
| 548 | {
|
|---|
| 549 | if (ColorDock *dock = qobject_cast<ColorDock*>(widget()))
|
|---|
| 550 | dock->setCustomSizeHint(size);
|
|---|
| 551 | }
|
|---|
| 552 |
|
|---|
| 553 | void ColorSwatch::changeClosable(bool on)
|
|---|
| 554 | { setFeatures(on ? features() | DockWidgetClosable : features() & ~DockWidgetClosable); }
|
|---|
| 555 |
|
|---|
| 556 | void ColorSwatch::changeMovable(bool on)
|
|---|
| 557 | { setFeatures(on ? features() | DockWidgetMovable : features() & ~DockWidgetMovable); }
|
|---|
| 558 |
|
|---|
| 559 | void ColorSwatch::changeFloatable(bool on)
|
|---|
| 560 | { setFeatures(on ? features() | DockWidgetFloatable : features() & ~DockWidgetFloatable); }
|
|---|
| 561 |
|
|---|
| 562 | void ColorSwatch::changeFloating(bool floating)
|
|---|
| 563 | { setFloating(floating); }
|
|---|
| 564 |
|
|---|
| 565 | void ColorSwatch::allowLeft(bool a)
|
|---|
| 566 | { allow(Qt::LeftDockWidgetArea, a); }
|
|---|
| 567 |
|
|---|
| 568 | void ColorSwatch::allowRight(bool a)
|
|---|
| 569 | { allow(Qt::RightDockWidgetArea, a); }
|
|---|
| 570 |
|
|---|
| 571 | void ColorSwatch::allowTop(bool a)
|
|---|
| 572 | { allow(Qt::TopDockWidgetArea, a); }
|
|---|
| 573 |
|
|---|
| 574 | void ColorSwatch::allowBottom(bool a)
|
|---|
| 575 | { allow(Qt::BottomDockWidgetArea, a); }
|
|---|
| 576 |
|
|---|
| 577 | void ColorSwatch::placeLeft(bool p)
|
|---|
| 578 | { place(Qt::LeftDockWidgetArea, p); }
|
|---|
| 579 |
|
|---|
| 580 | void ColorSwatch::placeRight(bool p)
|
|---|
| 581 | { place(Qt::RightDockWidgetArea, p); }
|
|---|
| 582 |
|
|---|
| 583 | void ColorSwatch::placeTop(bool p)
|
|---|
| 584 | { place(Qt::TopDockWidgetArea, p); }
|
|---|
| 585 |
|
|---|
| 586 | void ColorSwatch::placeBottom(bool p)
|
|---|
| 587 | { place(Qt::BottomDockWidgetArea, p); }
|
|---|
| 588 |
|
|---|
| 589 | void ColorSwatch::changeVerticalTitleBar(bool on)
|
|---|
| 590 | {
|
|---|
| 591 | setFeatures(on ? features() | DockWidgetVerticalTitleBar
|
|---|
| 592 | : features() & ~DockWidgetVerticalTitleBar);
|
|---|
| 593 | }
|
|---|
| 594 |
|
|---|
| 595 | QSize BlueTitleBar::minimumSizeHint() const
|
|---|
| 596 | {
|
|---|
| 597 | QDockWidget *dw = qobject_cast<QDockWidget*>(parentWidget());
|
|---|
| 598 | Q_ASSERT(dw != 0);
|
|---|
| 599 | QSize result(leftPm.width() + rightPm.width(), centerPm.height());
|
|---|
| 600 | if (dw->features() & QDockWidget::DockWidgetVerticalTitleBar)
|
|---|
| 601 | result.transpose();
|
|---|
| 602 | return result;
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 | BlueTitleBar::BlueTitleBar(QWidget *parent)
|
|---|
| 606 | : QWidget(parent)
|
|---|
| 607 | {
|
|---|
| 608 | leftPm = QPixmap(":/res/titlebarLeft.png");
|
|---|
| 609 | centerPm = QPixmap(":/res/titlebarCenter.png");
|
|---|
| 610 | rightPm = QPixmap(":/res/titlebarRight.png");
|
|---|
| 611 | }
|
|---|
| 612 |
|
|---|
| 613 | void BlueTitleBar::paintEvent(QPaintEvent*)
|
|---|
| 614 | {
|
|---|
| 615 | QPainter painter(this);
|
|---|
| 616 | QRect rect = this->rect();
|
|---|
| 617 |
|
|---|
| 618 | QDockWidget *dw = qobject_cast<QDockWidget*>(parentWidget());
|
|---|
| 619 | Q_ASSERT(dw != 0);
|
|---|
| 620 |
|
|---|
| 621 | if (dw->features() & QDockWidget::DockWidgetVerticalTitleBar) {
|
|---|
| 622 | QSize s = rect.size();
|
|---|
| 623 | s.transpose();
|
|---|
| 624 | rect.setSize(s);
|
|---|
| 625 |
|
|---|
| 626 | painter.translate(rect.left(), rect.top() + rect.width());
|
|---|
| 627 | painter.rotate(-90);
|
|---|
| 628 | painter.translate(-rect.left(), -rect.top());
|
|---|
| 629 | }
|
|---|
| 630 |
|
|---|
| 631 | painter.drawPixmap(rect.topLeft(), leftPm);
|
|---|
| 632 | painter.drawPixmap(rect.topRight() - QPoint(rightPm.width() - 1, 0), rightPm);
|
|---|
| 633 | QBrush brush(centerPm);
|
|---|
| 634 | painter.fillRect(rect.left() + leftPm.width(), rect.top(),
|
|---|
| 635 | rect.width() - leftPm.width() - rightPm.width(),
|
|---|
| 636 | centerPm.height(), centerPm);
|
|---|
| 637 | }
|
|---|
| 638 |
|
|---|
| 639 | void BlueTitleBar::mousePressEvent(QMouseEvent *event)
|
|---|
| 640 | {
|
|---|
| 641 | QPoint pos = event->pos();
|
|---|
| 642 |
|
|---|
| 643 | QRect rect = this->rect();
|
|---|
| 644 |
|
|---|
| 645 | QDockWidget *dw = qobject_cast<QDockWidget*>(parentWidget());
|
|---|
| 646 | Q_ASSERT(dw != 0);
|
|---|
| 647 |
|
|---|
| 648 | if (dw->features() & QDockWidget::DockWidgetVerticalTitleBar) {
|
|---|
| 649 | QPoint p = pos;
|
|---|
| 650 | pos.setX(rect.left() + rect.bottom() - p.y());
|
|---|
| 651 | pos.setY(rect.top() + p.x() - rect.left());
|
|---|
| 652 |
|
|---|
| 653 | QSize s = rect.size();
|
|---|
| 654 | s.transpose();
|
|---|
| 655 | rect.setSize(s);
|
|---|
| 656 | }
|
|---|
| 657 |
|
|---|
| 658 | const int buttonRight = 7;
|
|---|
| 659 | const int buttonWidth = 20;
|
|---|
| 660 | int right = rect.right() - pos.x();
|
|---|
| 661 | int button = (right - buttonRight)/buttonWidth;
|
|---|
| 662 | switch (button) {
|
|---|
| 663 | case 0:
|
|---|
| 664 | event->accept();
|
|---|
| 665 | dw->close();
|
|---|
| 666 | break;
|
|---|
| 667 | case 1:
|
|---|
| 668 | event->accept();
|
|---|
| 669 | dw->setFloating(!dw->isFloating());
|
|---|
| 670 | break;
|
|---|
| 671 | case 2: {
|
|---|
| 672 | event->accept();
|
|---|
| 673 | QDockWidget::DockWidgetFeatures features = dw->features();
|
|---|
| 674 | if (features & QDockWidget::DockWidgetVerticalTitleBar)
|
|---|
| 675 | features &= ~QDockWidget::DockWidgetVerticalTitleBar;
|
|---|
| 676 | else
|
|---|
| 677 | features |= QDockWidget::DockWidgetVerticalTitleBar;
|
|---|
| 678 | dw->setFeatures(features);
|
|---|
| 679 | break;
|
|---|
| 680 | }
|
|---|
| 681 | default:
|
|---|
| 682 | event->ignore();
|
|---|
| 683 | break;
|
|---|
| 684 | }
|
|---|
| 685 | }
|
|---|
| 686 |
|
|---|
| 687 | void BlueTitleBar::updateMask()
|
|---|
| 688 | {
|
|---|
| 689 | QDockWidget *dw = qobject_cast<QDockWidget*>(parent());
|
|---|
| 690 | Q_ASSERT(dw != 0);
|
|---|
| 691 |
|
|---|
| 692 | QRect rect = dw->rect();
|
|---|
| 693 | QPixmap bitmap(dw->size());
|
|---|
| 694 |
|
|---|
| 695 | {
|
|---|
| 696 | QPainter painter(&bitmap);
|
|---|
| 697 |
|
|---|
| 698 | ///initialize to transparent
|
|---|
| 699 | painter.fillRect(rect, Qt::color0);
|
|---|
| 700 |
|
|---|
| 701 | QRect contents = rect;
|
|---|
| 702 | contents.setTopLeft(geometry().bottomLeft());
|
|---|
| 703 | contents.setRight(geometry().right());
|
|---|
| 704 | contents.setBottom(contents.bottom()-y());
|
|---|
| 705 | painter.fillRect(contents, Qt::color1);
|
|---|
| 706 |
|
|---|
| 707 |
|
|---|
| 708 |
|
|---|
| 709 | //let's pait the titlebar
|
|---|
| 710 |
|
|---|
| 711 | QRect titleRect = this->geometry();
|
|---|
| 712 |
|
|---|
| 713 | if (dw->features() & QDockWidget::DockWidgetVerticalTitleBar) {
|
|---|
| 714 | QSize s = rect.size();
|
|---|
| 715 | s.transpose();
|
|---|
| 716 | rect.setSize(s);
|
|---|
| 717 |
|
|---|
| 718 | QSize s2 = size();
|
|---|
| 719 | s2.transpose();
|
|---|
| 720 | titleRect.setSize(s2);
|
|---|
| 721 |
|
|---|
| 722 | painter.translate(rect.left(), rect.top() + rect.width());
|
|---|
| 723 | painter.rotate(-90);
|
|---|
| 724 | painter.translate(-rect.left(), -rect.top());
|
|---|
| 725 | }
|
|---|
| 726 |
|
|---|
| 727 | contents.setTopLeft(titleRect.bottomLeft());
|
|---|
| 728 | contents.setRight(titleRect.right());
|
|---|
| 729 | contents.setBottom(rect.bottom()-y());
|
|---|
| 730 |
|
|---|
| 731 | QRect rect = titleRect;
|
|---|
| 732 |
|
|---|
| 733 |
|
|---|
| 734 | painter.drawPixmap(rect.topLeft(), leftPm.mask());
|
|---|
| 735 | painter.fillRect(rect.left() + leftPm.width(), rect.top(),
|
|---|
| 736 | rect.width() - leftPm.width() - rightPm.width(),
|
|---|
| 737 | centerPm.height(), Qt::color1);
|
|---|
| 738 | painter.drawPixmap(rect.topRight() - QPoint(rightPm.width() - 1, 0), rightPm.mask());
|
|---|
| 739 |
|
|---|
| 740 | painter.fillRect(contents, Qt::color1);
|
|---|
| 741 | }
|
|---|
| 742 |
|
|---|
| 743 | dw->setMask(bitmap);
|
|---|
| 744 | }
|
|---|
| 745 |
|
|---|
| 746 | #include "colorswatch.moc"
|
|---|