/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the demonstration applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** 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.1, 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.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/#include "colorswatch.h"#include <QAction>#include <QtEvents>#include <QFrame>#include <QMainWindow>#include <QMenu>#include <QPainter>#include <QImage>#include <QColor>#include <QDialog>#include <QGridLayout>#include <QSpinBox>#include <QLabel>#include <QPainterPath>#include <QPushButton>#include <QHBoxLayout>#include <QBitmap>#include <QtDebug>#undef DEBUG_SIZEHINTSQColor bgColorForName(constQString&name)
{
if (name =="Black")
returnQColor("#D8D8D8");
elseif (name =="White")
returnQColor("#F1F1F1");
elseif (name =="Red")
returnQColor("#F1D8D8");
elseif (name =="Green")
returnQColor("#D8E4D8");
elseif (name =="Blue")
returnQColor("#D8D8F1");
elseif (name =="Yellow")
returnQColor("#F1F0D8");
returnQColor(name).light(110);
}
QColor fgColorForName(constQString&name)
{
if (name =="Black")
returnQColor("#6C6C6C");
elseif (name =="White")
returnQColor("#F8F8F8");
elseif (name =="Red")
returnQColor("#F86C6C");
elseif (name =="Green")
returnQColor("#6CB26C");
elseif (name =="Blue")
returnQColor("#6C6CF8");
elseif (name =="Yellow")
returnQColor("#F8F76C");
returnQColor(name);
}
class ColorDock : publicQFrame
{
Q_OBJECT
public:
ColorDock(constQString&c,QWidget*parent);
virtualQSize sizeHint() const;
virtualQSize minimumSizeHint() const;
void setCustomSizeHint(constQSize&size);
publicslots:
void changeSizeHints();
protected:
void paintEvent(QPaintEvent*);
QString color;
QSize szHint, minSzHint;
};
ColorDock::ColorDock(constQString&c,QWidget*parent)
: QFrame(parent) , color(c)
{
QFont font =this->font();
font.setPointSize(8);
setFont(font);
szHint =QSize(-1,-1);
minSzHint =QSize(125,75);
}
QSize ColorDock::sizeHint() const
{
return szHint;
}
QSize ColorDock::minimumSizeHint() const
{
return minSzHint;
}
void ColorDock::paintEvent(QPaintEvent*)
{
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.fillRect(rect(), bgColorForName(color));
p.save();
externvoid render_qt_text(QPainter*,int,int,constQColor&);
render_qt_text(&p, width(), height(), fgColorForName(color));
p.restore();
#ifdef DEBUG_SIZEHINTS
p.setRenderHint(QPainter::Antialiasing,false);
QSize sz = size();
QSize szHint = sizeHint();
QSize minSzHint = minimumSizeHint();
QSize maxSz = maximumSize();
QString text =QString::fromLatin1("sz: %1x%2\nszHint: %3x%4\nminSzHint: %5x%6\n""maxSz: %8x%9")
.arg(sz.width()).arg(sz.height())
.arg(szHint.width()).arg(szHint.height())
.arg(minSzHint.width()).arg(minSzHint.height())
.arg(maxSz.width()).arg(maxSz.height());
QRect r = fontMetrics().boundingRect(rect(),Qt::AlignLeft|Qt::AlignTop, text);
r.adjust(-2,-2,1,1);
p.translate(4,4);
QColor bg =Qt::yellow;
bg.setAlpha(120);
p.setBrush(bg);
p.setPen(Qt::black);
p.drawRect(r);
p.drawText(rect(),Qt::AlignLeft|Qt::AlignTop, text);
#endif // DEBUG_SIZEHINTS
}
staticQSpinBox*createSpinBox(int value,QWidget*parent,int max =1000)
{
QSpinBox*result =newQSpinBox(parent);
result->setMinimum(-1);
result->setMaximum(max);
result->setValue(value);
return result;
}
void ColorDock::changeSizeHints()
{
QDialog dialog(this);
dialog.setWindowTitle(color);
QVBoxLayout*topLayout =newQVBoxLayout(&dialog);
QGridLayout*inputLayout =newQGridLayout();
topLayout->addLayout(inputLayout);
inputLayout->addWidget(newQLabel(tr("Size Hint:"),&dialog),0,0);
inputLayout->addWidget(newQLabel(tr("Min Size Hint:"),&dialog),1,0);
inputLayout->addWidget(newQLabel(tr("Max Size:"),&dialog),2,0);
inputLayout->addWidget(newQLabel(tr("Dockwgt Max Size:"),&dialog),3,0);
QSpinBox*szHintW = createSpinBox(szHint.width(),&dialog);
inputLayout->addWidget(szHintW,0,1);
QSpinBox*szHintH = createSpinBox(szHint.height(),&dialog);
inputLayout->addWidget(szHintH,0,2);
QSpinBox*minSzHintW = createSpinBox(minSzHint.width(),&dialog);
inputLayout->addWidget(minSzHintW,1,1);
QSpinBox*minSzHintH = createSpinBox(minSzHint.height(),&dialog);
inputLayout->addWidget(minSzHintH,1,2);
QSize maxSz = maximumSize();
QSpinBox*maxSzW = createSpinBox(maxSz.width(),&dialog, QWIDGETSIZE_MAX);
inputLayout->addWidget(maxSzW,2,1);
QSpinBox*maxSzH = createSpinBox(maxSz.height(),&dialog, QWIDGETSIZE_MAX);
inputLayout->addWidget(maxSzH,2,2);
QSize dwMaxSz = parentWidget()->maximumSize();
QSpinBox*dwMaxSzW = createSpinBox(dwMaxSz.width(),&dialog, QWIDGETSIZE_MAX);
inputLayout->addWidget(dwMaxSzW,3,1);
QSpinBox*dwMaxSzH = createSpinBox(dwMaxSz.height(),&dialog, QWIDGETSIZE_MAX);
inputLayout->addWidget(dwMaxSzH,3,2);
inputLayout->setColumnStretch(1,1);
inputLayout->setColumnStretch(2,1);
topLayout->addStretch();
QHBoxLayout*buttonBox =newQHBoxLayout();
topLayout->addLayout(buttonBox);
QPushButton*okButton =newQPushButton(tr("Ok"),&dialog);
QPushButton*cancelButton =newQPushButton(tr("Cancel"),&dialog);
connect(okButton, SIGNAL(clicked()),&dialog, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()),&dialog, SLOT(reject()));
buttonBox->addStretch();
buttonBox->addWidget(cancelButton);
buttonBox->addWidget(okButton);
if (!dialog.exec())
return;
szHint =QSize(szHintW->value(), szHintH->value());
minSzHint =QSize(minSzHintW->value(), minSzHintH->value());
maxSz =QSize(maxSzW->value(), maxSzH->value());
setMaximumSize(maxSz);
dwMaxSz =QSize(dwMaxSzW->value(), dwMaxSzH->value());
parentWidget()->setMaximumSize(dwMaxSz);
updateGeometry();
update();
}
void ColorDock::setCustomSizeHint(constQSize&size)
{
szHint = size;
updateGeometry();
}
ColorSwatch::ColorSwatch(constQString&colorName,QWidget*parent,Qt::WindowFlags flags)
: QDockWidget(parent, flags)
{
setObjectName(colorName + QLatin1String(" Dock Widget"));
setWindowTitle(objectName() + QLatin1String(" [*]"));
QFrame*swatch =new ColorDock(colorName,this);
swatch->setFrameStyle(QFrame::Box |QFrame::Sunken);
setWidget(swatch);
changeSizeHintsAction =newQAction(tr("Change Size Hints"),this);
connect(changeSizeHintsAction, SIGNAL(triggered()), swatch, SLOT(changeSizeHints()));
closableAction =newQAction(tr("Closable"),this);
closableAction->setCheckable(true);
connect(closableAction, SIGNAL(triggered(bool)), SLOT(changeClosable(bool)));
movableAction =newQAction(tr("Movable"),this);
movableAction->setCheckable(true);
connect(movableAction, SIGNAL(triggered(bool)), SLOT(changeMovable(bool)));
floatableAction =newQAction(tr("Floatable"),this);
floatableAction->setCheckable(true);
connect(floatableAction, SIGNAL(triggered(bool)), SLOT(changeFloatable(bool)));
verticalTitleBarAction =newQAction(tr("Vertical title bar"),this);
verticalTitleBarAction->setCheckable(true);
connect(verticalTitleBarAction, SIGNAL(triggered(bool)),
SLOT(changeVerticalTitleBar(bool)));
floatingAction =newQAction(tr("Floating"),this);
floatingAction->setCheckable(true);
connect(floatingAction, SIGNAL(triggered(bool)), SLOT(changeFloating(bool)));
allowedAreasActions =newQActionGroup(this);
allowedAreasActions->setExclusive(false);
allowLeftAction =newQAction(tr("Allow on Left"),this);
allowLeftAction->setCheckable(true);
connect(allowLeftAction, SIGNAL(triggered(bool)), SLOT(allowLeft(bool)));
allowRightAction =newQAction(tr("Allow on Right"),this);
allowRightAction->setCheckable(true);
connect(allowRightAction, SIGNAL(triggered(bool)), SLOT(allowRight(bool)));
allowTopAction =newQAction(tr("Allow on Top"),this);
allowTopAction->setCheckable(true);
connect(allowTopAction, SIGNAL(triggered(bool)), SLOT(allowTop(bool)));
allowBottomAction =newQAction(tr("Allow on Bottom"),this);
allowBottomAction->setCheckable(true);
connect(allowBottomAction, SIGNAL(triggered(bool)), SLOT(allowBottom(bool)));
allowedAreasActions->addAction(allowLeftAction);
allowedAreasActions->addAction(allowRightAction);
allowedAreasActions->addAction(allowTopAction);
allowedAreasActions->addAction(allowBottomAction);
areaActions =newQActionGroup(this);
areaActions->setExclusive(true);
leftAction =newQAction(tr("Place on Left") ,this);
leftAction->setCheckable(true);
connect(leftAction, SIGNAL(triggered(bool)), SLOT(placeLeft(bool)));
rightAction =newQAction(tr("Place on Right") ,this);
rightAction->setCheckable(true);
connect(rightAction, SIGNAL(triggered(bool)), SLOT(placeRight(bool)));
topAction =newQAction(tr("Place on Top") ,this);
topAction->setCheckable(true);
connect(topAction, SIGNAL(triggered(bool)), SLOT(placeTop(bool)));
bottomAction =newQAction(tr("Place on Bottom") ,this);
bottomAction->setCheckable(true);
connect(bottomAction, SIGNAL(triggered(bool)), SLOT(placeBottom(bool)));
areaActions->addAction(leftAction);
areaActions->addAction(rightAction);
areaActions->addAction(topAction);
areaActions->addAction(bottomAction);
connect(movableAction, SIGNAL(triggered(bool)), areaActions, SLOT(setEnabled(bool)));
connect(movableAction, SIGNAL(triggered(bool)), allowedAreasActions, SLOT(setEnabled(bool)));
connect(floatableAction, SIGNAL(triggered(bool)), floatingAction, SLOT(setEnabled(bool)));
connect(floatingAction, SIGNAL(triggered(bool)), floatableAction, SLOT(setDisabled(bool)));
connect(movableAction, SIGNAL(triggered(bool)), floatableAction, SLOT(setEnabled(bool)));
tabMenu =newQMenu(this);
tabMenu->setTitle(tr("Tab into"));
connect(tabMenu, SIGNAL(triggered(QAction*)),this, SLOT(tabInto(QAction*)));
splitHMenu =newQMenu(this);
splitHMenu->setTitle(tr("Split horizontally into"));
connect(splitHMenu, SIGNAL(triggered(QAction*)),this, SLOT(splitInto(QAction*)));
splitVMenu =newQMenu(this);
splitVMenu->setTitle(tr("Split vertically into"));
connect(splitVMenu, SIGNAL(triggered(QAction*)),this, SLOT(splitInto(QAction*)));
windowModifiedAction =newQAction(tr("Modified"),this);
windowModifiedAction->setCheckable(true);
windowModifiedAction->setChecked(false);
connect(windowModifiedAction, SIGNAL(toggled(bool)),this, SLOT(setWindowModified(bool)));
menu =newQMenu(colorName,this);
menu->addAction(toggleViewAction());
QAction*action = menu->addAction(tr("Raise"));
connect(action, SIGNAL(triggered()),this, SLOT(raise()));
menu->addAction(changeSizeHintsAction);
menu->addSeparator();
menu->addAction(closableAction);
menu->addAction(movableAction);
menu->addAction(floatableAction);
menu->addAction(floatingAction);
menu->addAction(verticalTitleBarAction);
menu->addSeparator();
menu->addActions(allowedAreasActions->actions());
menu->addSeparator();
menu->addActions(areaActions->actions());
menu->addSeparator();
menu->addMenu(splitHMenu);
menu->addMenu(splitVMenu);
menu->addMenu(tabMenu);
menu->addSeparator();
menu->addAction(windowModifiedAction);
connect(menu, SIGNAL(aboutToShow()),this, SLOT(updateContextMenu()));
if(colorName =="Black") {
leftAction->setShortcut(Qt::CTRL|Qt::Key_W);
rightAction->setShortcut(Qt::CTRL|Qt::Key_E);
toggleViewAction()->setShortcut(Qt::CTRL|Qt::Key_R);
}
}
void ColorSwatch::updateContextMenu()
{
QMainWindow*mainWindow = qobject_cast<QMainWindow*>(parentWidget());
constQt::DockWidgetArea area = mainWindow->dockWidgetArea(this);
constQt::DockWidgetAreas areas = allowedAreas();
closableAction->setChecked(features() &QDockWidget::DockWidgetClosable);
if (windowType() ==Qt::Drawer) {
floatableAction->setEnabled(false);
floatingAction->setEnabled(false);
movableAction->setEnabled(false);
verticalTitleBarAction->setChecked(false);
} else {
floatableAction->setChecked(features() &QDockWidget::DockWidgetFloatable);
floatingAction->setChecked(isWindow());
// done after floating, to get 'floatable' correctly initialized
movableAction->setChecked(features() &QDockWidget::DockWidgetMovable);
verticalTitleBarAction
->setChecked(features() &QDockWidget::DockWidgetVerticalTitleBar);
}
allowLeftAction->setChecked(isAreaAllowed(Qt::LeftDockWidgetArea));
allowRightAction->setChecked(isAreaAllowed(Qt::RightDockWidgetArea));
allowTopAction->setChecked(isAreaAllowed(Qt::TopDockWidgetArea));
allowBottomAction->setChecked(isAreaAllowed(Qt::BottomDockWidgetArea));
if (allowedAreasActions->isEnabled()) {
allowLeftAction->setEnabled(area !=Qt::LeftDockWidgetArea);
allowRightAction->setEnabled(area !=Qt::RightDockWidgetArea);
allowTopAction->setEnabled(area !=Qt::TopDockWidgetArea);
allowBottomAction->setEnabled(area !=Qt::BottomDockWidgetArea);
}
leftAction->blockSignals(true);
rightAction->blockSignals(true);
topAction->blockSignals(true);
bottomAction->blockSignals(true);
leftAction->setChecked(area ==Qt::LeftDockWidgetArea);
rightAction->setChecked(area ==Qt::RightDockWidgetArea);
topAction->setChecked(area ==Qt::TopDockWidgetArea);
bottomAction->setChecked(area ==Qt::BottomDockWidgetArea);
leftAction->blockSignals(false);
rightAction->blockSignals(false);
topAction->blockSignals(false);
bottomAction->blockSignals(false);
if (areaActions->isEnabled()) {
leftAction->setEnabled(areas &Qt::LeftDockWidgetArea);
rightAction->setEnabled(areas &Qt::RightDockWidgetArea);
topAction->setEnabled(areas &Qt::TopDockWidgetArea);
bottomAction->setEnabled(areas &Qt::BottomDockWidgetArea);
}
tabMenu->clear();
splitHMenu->clear();
splitVMenu->clear();
QList<ColorSwatch*> dock_list = mainWindow->findChildren<ColorSwatch*>();
foreach (ColorSwatch *dock, dock_list) {
// if (!dock->isVisible() || dock->isFloating())// continue;
tabMenu->addAction(dock->objectName());
splitHMenu->addAction(dock->objectName());
splitVMenu->addAction(dock->objectName());
}
}
void ColorSwatch::splitInto(QAction*action)
{
QMainWindow*mainWindow = qobject_cast<QMainWindow*>(parentWidget());
QList<ColorSwatch*> dock_list = mainWindow->findChildren<ColorSwatch*>();
ColorSwatch *target =0;
foreach (ColorSwatch *dock, dock_list) {
if (action->text() == dock->objectName()) {
target = dock;
break;
}
}
if (target ==0)
return;
Qt::Orientation o = action->parent() == splitHMenu
?Qt::Horizontal : Qt::Vertical;
mainWindow->splitDockWidget(target,this, o);
}
void ColorSwatch::tabInto(QAction*action)
{
QMainWindow*mainWindow = qobject_cast<QMainWindow*>(parentWidget());
QList<ColorSwatch*> dock_list = mainWindow->findChildren<ColorSwatch*>();
ColorSwatch *target =0;
foreach (ColorSwatch *dock, dock_list) {
if (action->text() == dock->objectName()) {
target = dock;
break;
}
}
if (target ==0)
return;
mainWindow->tabifyDockWidget(target,this);
}
void ColorSwatch::contextMenuEvent(QContextMenuEvent*event)
{
event->accept();
menu->exec(event->globalPos());
}
void ColorSwatch::resizeEvent(QResizeEvent*e)
{
if (BlueTitleBar *btb = qobject_cast<BlueTitleBar*>(titleBarWidget()))
btb->updateMask();
QDockWidget::resizeEvent(e);
}
void ColorSwatch::allow(Qt::DockWidgetArea area,bool a)
{
Qt::DockWidgetAreas areas = allowedAreas();
areas = a ? areas | area : areas &~area;
setAllowedAreas(areas);
if (areaActions->isEnabled()) {
leftAction->setEnabled(areas &Qt::LeftDockWidgetArea);
rightAction->setEnabled(areas &Qt::RightDockWidgetArea);
topAction->setEnabled(areas &Qt::TopDockWidgetArea);
bottomAction->setEnabled(areas &Qt::BottomDockWidgetArea);
}
}
void ColorSwatch::place(Qt::DockWidgetArea area,bool p)
{
if (!p) return;
QMainWindow*mainWindow = qobject_cast<QMainWindow*>(parentWidget());
mainWindow->addDockWidget(area,this);
if (allowedAreasActions->isEnabled()) {
allowLeftAction->setEnabled(area !=Qt::LeftDockWidgetArea);
allowRightAction->setEnabled(area !=Qt::RightDockWidgetArea);
allowTopAction->setEnabled(area !=Qt::TopDockWidgetArea);
allowBottomAction->setEnabled(area !=Qt::BottomDockWidgetArea);
}
}
void ColorSwatch::setCustomSizeHint(constQSize&size)
{
if (ColorDock *dock = qobject_cast<ColorDock*>(widget()))
dock->setCustomSizeHint(size);
}
void ColorSwatch::changeClosable(bool on)
{ setFeatures(on ? features() | DockWidgetClosable : features() &~DockWidgetClosable); }
void ColorSwatch::changeMovable(bool on)
{ setFeatures(on ? features() | DockWidgetMovable : features() &~DockWidgetMovable); }
void ColorSwatch::changeFloatable(bool on)
{ setFeatures(on ? features() | DockWidgetFloatable : features() &~DockWidgetFloatable); }
void ColorSwatch::changeFloating(bool floating)
{ setFloating(floating); }
void ColorSwatch::allowLeft(bool a)
{ allow(Qt::LeftDockWidgetArea, a); }
void ColorSwatch::allowRight(bool a)
{ allow(Qt::RightDockWidgetArea, a); }
void ColorSwatch::allowTop(bool a)
{ allow(Qt::TopDockWidgetArea, a); }
void ColorSwatch::allowBottom(bool a)
{ allow(Qt::BottomDockWidgetArea, a); }
void ColorSwatch::placeLeft(bool p)
{ place(Qt::LeftDockWidgetArea, p); }
void ColorSwatch::placeRight(bool p)
{ place(Qt::RightDockWidgetArea, p); }
void ColorSwatch::placeTop(bool p)
{ place(Qt::TopDockWidgetArea, p); }
void ColorSwatch::placeBottom(bool p)
{ place(Qt::BottomDockWidgetArea, p); }
void ColorSwatch::changeVerticalTitleBar(bool on)
{
setFeatures(on ? features() | DockWidgetVerticalTitleBar
: features() &~DockWidgetVerticalTitleBar);
}
QSize BlueTitleBar::minimumSizeHint() const
{
QDockWidget*dw = qobject_cast<QDockWidget*>(parentWidget());
Q_ASSERT(dw !=0);
QSize result(leftPm.width() + rightPm.width(), centerPm.height());
if (dw->features() &QDockWidget::DockWidgetVerticalTitleBar)
result.transpose();
return result;
}
BlueTitleBar::BlueTitleBar(QWidget*parent)
: QWidget(parent)
{
leftPm =QPixmap(":/res/titlebarLeft.png");
centerPm =QPixmap(":/res/titlebarCenter.png");
rightPm =QPixmap(":/res/titlebarRight.png");
}
void BlueTitleBar::paintEvent(QPaintEvent*)
{
QPainter painter(this);
QRect rect =this->rect();
QDockWidget*dw = qobject_cast<QDockWidget*>(parentWidget());
Q_ASSERT(dw !=0);
if (dw->features() &QDockWidget::DockWidgetVerticalTitleBar) {
QSize s = rect.size();
s.transpose();
rect.setSize(s);
painter.translate(rect.left(), rect.top() + rect.width());
painter.rotate(-90);
painter.translate(-rect.left(),-rect.top());
}
painter.drawPixmap(rect.topLeft(), leftPm);
painter.drawPixmap(rect.topRight() -QPoint(rightPm.width() -1,0), rightPm);
QBrush brush(centerPm);
painter.fillRect(rect.left() + leftPm.width(), rect.top(),
rect.width() - leftPm.width() - rightPm.width(),
centerPm.height(), centerPm);
}
void BlueTitleBar::mousePressEvent(QMouseEvent*event)
{
QPoint pos = event->pos();
QRect rect =this->rect();
QDockWidget*dw = qobject_cast<QDockWidget*>(parentWidget());
Q_ASSERT(dw !=0);
if (dw->features() &QDockWidget::DockWidgetVerticalTitleBar) {
QPoint p = pos;
pos.setX(rect.left() + rect.bottom() - p.y());
pos.setY(rect.top() + p.x() - rect.left());
QSize s = rect.size();
s.transpose();
rect.setSize(s);
}
constint buttonRight =7;
constint buttonWidth =20;
int right = rect.right() - pos.x();
int button = (right - buttonRight)/buttonWidth;
switch (button) {
case0:
event->accept();
dw->close();
break;
case1:
event->accept();
dw->setFloating(!dw->isFloating());
break;
case2: {
event->accept();
QDockWidget::DockWidgetFeatures features = dw->features();
if (features &QDockWidget::DockWidgetVerticalTitleBar)
features &=~QDockWidget::DockWidgetVerticalTitleBar;
else
features |=QDockWidget::DockWidgetVerticalTitleBar;
dw->setFeatures(features);
break;
}
default:
event->ignore();
break;
}
}
void BlueTitleBar::updateMask()
{
QDockWidget*dw = qobject_cast<QDockWidget*>(parent());
Q_ASSERT(dw !=0);
QRect rect = dw->rect();
QPixmap bitmap(dw->size());
{
QPainter painter(&bitmap);
///initialize to transparent
painter.fillRect(rect,Qt::color0);
QRect contents = rect;
contents.setTopLeft(geometry().bottomLeft());
contents.setRight(geometry().right());
contents.setBottom(contents.bottom()-y());
painter.fillRect(contents,Qt::color1);
//let's pait the titlebarQRect titleRect =this->geometry();
if (dw->features() &QDockWidget::DockWidgetVerticalTitleBar) {
QSize s = rect.size();
s.transpose();
rect.setSize(s);
QSize s2 = size();
s2.transpose();
titleRect.setSize(s2);
painter.translate(rect.left(), rect.top() + rect.width());
painter.rotate(-90);
painter.translate(-rect.left(),-rect.top());
}
contents.setTopLeft(titleRect.bottomLeft());
contents.setRight(titleRect.right());
contents.setBottom(rect.bottom()-y());
QRect rect = titleRect;
painter.drawPixmap(rect.topLeft(), leftPm.mask());
painter.fillRect(rect.left() + leftPm.width(), rect.top(),
rect.width() - leftPm.width() - rightPm.width(),
centerPm.height(),Qt::color1);
painter.drawPixmap(rect.topRight() -QPoint(rightPm.width() -1,0), rightPm.mask());
painter.fillRect(contents,Qt::color1);
}
dw->setMask(bitmap);
}
#include "colorswatch.moc"
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter
ou par MP !