diff options
Diffstat (limited to 'examples/qws/simpledecoration')
-rw-r--r-- | examples/qws/simpledecoration/analogclock.cpp | 110 | ||||
-rw-r--r-- | examples/qws/simpledecoration/analogclock.h | 57 | ||||
-rw-r--r-- | examples/qws/simpledecoration/main.cpp | 59 | ||||
-rw-r--r-- | examples/qws/simpledecoration/mydecoration.cpp | 374 | ||||
-rw-r--r-- | examples/qws/simpledecoration/mydecoration.h | 72 | ||||
-rw-r--r-- | examples/qws/simpledecoration/simpledecoration.pro | 12 |
6 files changed, 684 insertions, 0 deletions
diff --git a/examples/qws/simpledecoration/analogclock.cpp b/examples/qws/simpledecoration/analogclock.cpp new file mode 100644 index 0000000000..4a91e0dc0a --- /dev/null +++ b/examples/qws/simpledecoration/analogclock.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "analogclock.h" + +AnalogClock::AnalogClock(QWidget *parent) + : QWidget(parent) +{ + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(update())); + timer->start(1000); + + setWindowTitle(tr("Analog Clock")); + resize(200, 200); +} + +void AnalogClock::paintEvent(QPaintEvent *) +{ + static const QPoint hourHand[3] = { + QPoint(7, 8), + QPoint(-7, 8), + QPoint(0, -40) + }; + static const QPoint minuteHand[3] = { + QPoint(7, 8), + QPoint(-7, 8), + QPoint(0, -70) + }; + + QColor hourColor(127, 0, 127); + QColor minuteColor(0, 127, 127, 191); + + int side = qMin(width(), height()); + QTime time = QTime::currentTime(); + + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.translate(width() / 2, height() / 2); + painter.scale(side / 200.0, side / 200.0); + + painter.setPen(Qt::NoPen); + painter.setBrush(hourColor); + + painter.save(); + painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0))); + painter.drawConvexPolygon(hourHand, 3); + painter.restore(); + + painter.setPen(hourColor); + + for (int i = 0; i < 12; ++i) { + painter.drawLine(88, 0, 96, 0); + painter.rotate(30.0); + } + + painter.setPen(Qt::NoPen); + painter.setBrush(minuteColor); + + painter.save(); + painter.rotate(6.0 * (time.minute() + time.second() / 60.0)); + painter.drawConvexPolygon(minuteHand, 3); + painter.restore(); + + painter.setPen(minuteColor); + + for (int j = 0; j < 60; ++j) { + if ((j % 5) != 0) + painter.drawLine(92, 0, 96, 0); + painter.rotate(6.0); + } +} diff --git a/examples/qws/simpledecoration/analogclock.h b/examples/qws/simpledecoration/analogclock.h new file mode 100644 index 0000000000..6fef764ee1 --- /dev/null +++ b/examples/qws/simpledecoration/analogclock.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANALOGCLOCK_H +#define ANALOGCLOCK_H + +#include <QWidget> + +class AnalogClock : public QWidget +{ + Q_OBJECT + +public: + AnalogClock(QWidget *parent = 0); + +protected: + void paintEvent(QPaintEvent *event); +}; + +#endif diff --git a/examples/qws/simpledecoration/main.cpp b/examples/qws/simpledecoration/main.cpp new file mode 100644 index 0000000000..9a8f913ee5 --- /dev/null +++ b/examples/qws/simpledecoration/main.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include "analogclock.h" +#include "mydecoration.h" + +//! [create application] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MyDecoration *decoration = new MyDecoration(); + app.qwsSetDecoration(decoration); +//! [create application] + +//! [start application] + AnalogClock clock; + clock.show(); + + return app.exec(); +} +//! [start application] diff --git a/examples/qws/simpledecoration/mydecoration.cpp b/examples/qws/simpledecoration/mydecoration.cpp new file mode 100644 index 0000000000..32db90596e --- /dev/null +++ b/examples/qws/simpledecoration/mydecoration.cpp @@ -0,0 +1,374 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include "mydecoration.h" + +/* XPM */ +static const char * const _close_button[] = { +"16 16 3 1", +" c none", +". c #ffafaf", +"x c #000000", +" ", +" xxxxxxxxxxxxxx ", +" x............x ", +" x.x........x.x ", +" x..x......x..x ", +" x...x....x...x ", +" x....x..x....x ", +" x.....xx.....x ", +" x.....xx.....x ", +" x....x..x....x ", +" x...x....x...x ", +" x..x......x..x ", +" x.x........x.x ", +" x............x ", +" xxxxxxxxxxxxxx ", +" "}; + +static const char * const _normalize_button[] = { +"16 16 4 1", +" c none", +". c #dfdfff", +"o c #7f7f7f", +"x c #000000", +" ", +" xxxxxxxxxxxxxx ", +" xx...........x ", +" x.x..........x ", +" x..x..x......x ", +" x...xxx......x ", +" x...xxx......x ", +" x..xxxx......x ", +" x............x ", +" x.......xxxx.x ", +" x.......x..x.x ", +" x.......x..x.x ", +" x.......xxxx.x ", +" x............x ", +" xxxxxxxxxxxxxx ", +" "}; + +static const char * const _maximize_button[] = { +"16 16 4 1", +" c none", +". c #dfdfff", +"o c #7f7f7f", +"x c #000000", +" ", +" xxxxxxxxxxxxxx ", +" x............x ", +" x.......xxxx.x ", +" x........xxx.x ", +" x........xxx.x ", +" x.......x..x.x ", +" x......x.....x ", +" x.....x......x ", +" x.oooo.......x ", +" x.o..o.......x ", +" x.o..o.......x ", +" x.oooo.......x ", +" x............x ", +" xxxxxxxxxxxxxx ", +" "}; + +static const char * const _help_button[] = { +"16 16 3 1", +" c none", +". c #afffdf", +"x c #000000", +" ", +" xxxxxxxxxxxxxx ", +" x............x ", +" x....xxxx....x ", +" x..xx....xx..x ", +" x.xx......xx.x ", +" x.xx......xx.x ", +" x........xx..x ", +" x......xx....x ", +" x.....xx.....x ", +" x.....xx.....x ", +" x............x ", +" x.....xx.....x ", +" x............x ", +" xxxxxxxxxxxxxx ", +" "}; + +//! [constructor start] +MyDecoration::MyDecoration() + : QDecorationDefault() +{ + border = 4; + titleHeight = 24; + buttonWidth = 20; + buttonHeight = 20; + buttonMargin = 2; + buttonHints << Qt::Window + << Qt::WindowMaximizeButtonHint + << Qt::WindowContextHelpButtonHint; + //! [constructor start] + + //! [map window flags to decoration regions] + buttonHintMap[Qt::Window] = Close; + buttonHintMap[Qt::WindowMaximizeButtonHint] = Maximize; + buttonHintMap[Qt::WindowContextHelpButtonHint] = Help; + //! [map window flags to decoration regions] + + //! [map decoration regions to pixmaps] + normalButtonPixmaps[Close] = QPixmap(_close_button); + normalButtonPixmaps[Maximize] = QPixmap(_maximize_button); + normalButtonPixmaps[Normalize] = QPixmap(_normalize_button); + normalButtonPixmaps[Help] = QPixmap(_help_button); + + maximizedButtonPixmaps[Close] = QPixmap(_close_button); + maximizedButtonPixmaps[Maximize] = QPixmap(_normalize_button); + maximizedButtonPixmaps[Normalize] = QPixmap(_normalize_button); + maximizedButtonPixmaps[Help] = QPixmap(_help_button); + //! [map decoration regions to pixmaps] + + //! [constructor end] + stateRegions << Close << Maximize << Help; +} +//! [constructor end] + +//! [region start] +QRegion MyDecoration::region(const QWidget *widget, const QRect &insideRect, + int decorationRegion) +{ + //! [region start] + //! [calculate the positions of buttons based on the window flags used] + QHash<DecorationRegion, int> buttons; + Qt::WindowFlags flags = widget->windowFlags(); + int dx = -buttonMargin - buttonWidth; + + foreach (Qt::WindowType button, buttonHints) { + if (flags & button) { + int x = (buttons.size() + 1) * dx; + buttons[buttonHintMap[button]] = x; + } + } + //! [calculate the positions of buttons based on the window flags used] + + //! [calculate the extent of the title] + int titleRightMargin = buttons.size() * dx; + + QRect outsideRect(insideRect.left() - border, + insideRect.top() - titleHeight - border, + insideRect.width() + 2 * border, + insideRect.height() + titleHeight + 2 * border); + //! [calculate the extent of the title] + + //! [check for all regions] + QRegion region; + + if (decorationRegion == All) { + region += QRegion(outsideRect) - QRegion(insideRect); + return region; + } + //! [check for all regions] + + //! [compose a region based on the decorations specified] + if (decorationRegion & Title) { + QRect rect = outsideRect.adjusted(border, border, -border, 0); + rect.setHeight(titleHeight); + + // Adjust the width to accommodate buttons. + rect.setWidth(qMax(0, rect.width() + titleRightMargin)); + region += rect; + } + if (decorationRegion & Top) { + QRect rect = outsideRect.adjusted(border, 0, -border, 0); + rect.setHeight(border); + region += rect; + } + if (decorationRegion & Left) { + QRect rect = outsideRect.adjusted(0, border, 0, -border); + rect.setWidth(border); + region += rect; + } + if (decorationRegion & Right) { + QRect rect = outsideRect.adjusted(0, border, 0, -border); + rect.setLeft(rect.right() + 1 - border); + region += rect; + } + if (decorationRegion & Bottom) { + QRect rect = outsideRect.adjusted(border, 0, -border, 0); + rect.setTop(rect.bottom() + 1 - border); + region += rect; + } + if (decorationRegion & TopLeft) { + QRect rect = outsideRect; + rect.setWidth(border); + rect.setHeight(border); + region += rect; + } + if (decorationRegion & TopRight) { + QRect rect = outsideRect; + rect.setLeft(rect.right() + 1 - border); + rect.setHeight(border); + region += rect; + } + if (decorationRegion & BottomLeft) { + QRect rect = outsideRect; + rect.setWidth(border); + rect.setTop(rect.bottom() + 1 - border); + region += rect; + } + if (decorationRegion & BottomRight) { + QRect rect = outsideRect; + rect.setLeft(rect.right() + 1 - border); + rect.setTop(rect.bottom() + 1 - border); + region += rect; + } + //! [compose a region based on the decorations specified] + + //! [add a region for each button only if it is present] + foreach (QDecoration::DecorationRegion testRegion, stateRegions) { + if (decorationRegion & testRegion and buttons.contains(testRegion)) { + // Inside the title rectangle + QRect rect = outsideRect.adjusted(border, border, -border, 0); + rect.setHeight(titleHeight); + + dx = buttons[testRegion]; + rect.setLeft(rect.right() + 1 + dx); + rect.setWidth(buttonWidth + buttonMargin); + region += rect; + } + } + //! [add a region for each button only if it is present] + + //! [region end] + return region; +} +//! [region end] + +//! [paint start] +bool MyDecoration::paint(QPainter *painter, const QWidget *widget, + int decorationRegion, DecorationState state) +{ + if (decorationRegion == None) + return false; + //! [paint start] + + //! [paint different regions] + bool handled = false; + + QPalette palette = QApplication::palette(); + QHash<DecorationRegion, QPixmap> buttonPixmaps; + + if (widget->windowState() == Qt::WindowMaximized) + buttonPixmaps = maximizedButtonPixmaps; + else + buttonPixmaps = normalButtonPixmaps; + + if (decorationRegion & Title) { + QRect rect = QDecoration::region(widget, Title).boundingRect(); + painter->fillRect(rect, palette.brush(QPalette::Base)); + painter->save(); + painter->setPen(QPen(palette.color(QPalette::Text))); + painter->drawText(rect, Qt::AlignCenter, widget->windowTitle()); + painter->restore(); + handled = true; + } + if (decorationRegion & Top) { + QRect rect = QDecoration::region(widget, Top).boundingRect(); + painter->fillRect(rect, palette.brush(QPalette::Dark)); + handled = true; + } + if (decorationRegion & Left) { + QRect rect = QDecoration::region(widget, Left).boundingRect(); + painter->fillRect(rect, palette.brush(QPalette::Dark)); + handled = true; + } + if (decorationRegion & Right) { + QRect rect = QDecoration::region(widget, Right).boundingRect(); + painter->fillRect(rect, palette.brush(QPalette::Dark)); + handled = true; + } + if (decorationRegion & Bottom) { + QRect rect = QDecoration::region(widget, Bottom).boundingRect(); + painter->fillRect(rect, palette.brush(QPalette::Dark)); + handled = true; + } + if (decorationRegion & TopLeft) { + QRect rect = QDecoration::region(widget, TopLeft).boundingRect(); + painter->fillRect(rect, palette.brush(QPalette::Dark)); + handled = true; + } + if (decorationRegion & TopRight) { + QRect rect = QDecoration::region(widget, TopRight).boundingRect(); + painter->fillRect(rect, palette.brush(QPalette::Dark)); + handled = true; + } + if (decorationRegion & BottomLeft) { + QRect rect = QDecoration::region(widget, BottomLeft).boundingRect(); + painter->fillRect(rect, palette.brush(QPalette::Dark)); + handled = true; + } + if (decorationRegion & BottomRight) { + QRect rect = QDecoration::region(widget, BottomRight).boundingRect(); + painter->fillRect(rect, palette.brush(QPalette::Dark)); + handled = true; + } + //! [paint different regions] + + //! [paint buttons] + int margin = (titleHeight - 16) / 2; + Qt::WindowFlags flags = widget->windowFlags(); + + foreach (DecorationRegion testRegion, stateRegions) { + if (decorationRegion & testRegion && flags & buttonHintMap.key(testRegion)) { + QRect rect = QDecoration::region( + widget, testRegion).boundingRect(); + painter->fillRect(rect, palette.brush(QPalette::Base)); + + QRect buttonRect = rect.adjusted(0, margin, -buttonMargin - margin, + -buttonMargin); + painter->drawPixmap(buttonRect.topLeft(), buttonPixmaps[testRegion]); + handled = true; + } + } + //! [paint buttons] + + //! [paint end] + return handled; +} +//! [paint end] diff --git a/examples/qws/simpledecoration/mydecoration.h b/examples/qws/simpledecoration/mydecoration.h new file mode 100644 index 0000000000..6d8aebf6b2 --- /dev/null +++ b/examples/qws/simpledecoration/mydecoration.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MYDECORATION_H +#define MYDECORATION_H + +#include <QDecorationDefault> +#include <QHash> +#include <QPixmap> +#include <QRegion> +#include <Qt> + +//! [decoration class definition] +class MyDecoration : public QDecorationDefault +{ +public: + MyDecoration(); + QRegion region(const QWidget *widget, const QRect &insideRect, int decorationRegion); + bool paint(QPainter *painter, const QWidget *widget, int decorationRegion, DecorationState state); + +private: + int border; + int buttonHeight; + int buttonMargin; + int buttonWidth; + int titleHeight; + QHash<Qt::WindowType, DecorationRegion> buttonHintMap; + QHash<DecorationRegion, QPixmap> normalButtonPixmaps; + QHash<DecorationRegion, QPixmap> maximizedButtonPixmaps; + QVector<Qt::WindowType> buttonHints; + QVector<DecorationRegion> stateRegions; +}; +//! [decoration class definition] + +#endif diff --git a/examples/qws/simpledecoration/simpledecoration.pro b/examples/qws/simpledecoration/simpledecoration.pro new file mode 100644 index 0000000000..2a4e0be51c --- /dev/null +++ b/examples/qws/simpledecoration/simpledecoration.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +HEADERS = analogclock.h \ + mydecoration.h +SOURCES = analogclock.cpp \ + main.cpp \ + mydecoration.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/simpledecoration +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/simpledecoration +INSTALLS += target sources |