From 38be0d13830efd2d98281c645c3a60afe05ffece Mon Sep 17 00:00:00 2001 From: Qt by Nokia Date: Wed, 27 Apr 2011 12:05:43 +0200 Subject: Initial import from the monolithic Qt. This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12 --- demos/shared/arthurstyle.cpp | 452 ++++++++++++++++++++++ demos/shared/arthurstyle.h | 79 ++++ demos/shared/arthurwidgets.cpp | 371 ++++++++++++++++++ demos/shared/arthurwidgets.h | 137 +++++++ demos/shared/hoverpoints.cpp | 415 ++++++++++++++++++++ demos/shared/hoverpoints.h | 162 ++++++++ demos/shared/images/bg_pattern.png | Bin 0 -> 104 bytes demos/shared/images/button_normal_cap_left.png | Bin 0 -> 654 bytes demos/shared/images/button_normal_cap_right.png | Bin 0 -> 674 bytes demos/shared/images/button_normal_stretch.png | Bin 0 -> 185 bytes demos/shared/images/button_pressed_cap_left.png | Bin 0 -> 710 bytes demos/shared/images/button_pressed_cap_right.png | Bin 0 -> 785 bytes demos/shared/images/button_pressed_stretch.png | Bin 0 -> 217 bytes demos/shared/images/curve_thing_edit-6.png | Bin 0 -> 58097 bytes demos/shared/images/frame_bottom.png | Bin 0 -> 166 bytes demos/shared/images/frame_bottomleft.png | Bin 0 -> 602 bytes demos/shared/images/frame_bottomright.png | Bin 0 -> 553 bytes demos/shared/images/frame_left.png | Bin 0 -> 182 bytes demos/shared/images/frame_right.png | Bin 0 -> 175 bytes demos/shared/images/frame_top.png | Bin 0 -> 188 bytes demos/shared/images/frame_topleft.png | Bin 0 -> 801 bytes demos/shared/images/frame_topright.png | Bin 0 -> 851 bytes demos/shared/images/groupframe_bottom_left.png | Bin 0 -> 397 bytes demos/shared/images/groupframe_bottom_right.png | Bin 0 -> 383 bytes demos/shared/images/groupframe_bottom_stretch.png | Bin 0 -> 141 bytes demos/shared/images/groupframe_left_stretch.png | Bin 0 -> 132 bytes demos/shared/images/groupframe_right_stretch.png | Bin 0 -> 113 bytes demos/shared/images/groupframe_top_stretch.png | Bin 0 -> 115 bytes demos/shared/images/groupframe_topleft.png | Bin 0 -> 412 bytes demos/shared/images/groupframe_topright.png | Bin 0 -> 449 bytes demos/shared/images/line_dash_dot.png | Bin 0 -> 151 bytes demos/shared/images/line_dash_dot_dot.png | Bin 0 -> 155 bytes demos/shared/images/line_dashed.png | Bin 0 -> 121 bytes demos/shared/images/line_dotted.png | Bin 0 -> 116 bytes demos/shared/images/line_solid.png | Bin 0 -> 110 bytes demos/shared/images/radiobutton-off.png | Bin 0 -> 442 bytes demos/shared/images/radiobutton-on.png | Bin 0 -> 474 bytes demos/shared/images/radiobutton_off.png | Bin 0 -> 442 bytes demos/shared/images/radiobutton_on.png | Bin 0 -> 499 bytes demos/shared/images/slider_bar.png | Bin 0 -> 748 bytes demos/shared/images/slider_thumb_off.png | Bin 0 -> 823 bytes demos/shared/images/slider_thumb_on.png | Bin 0 -> 798 bytes demos/shared/images/title_cap_left.png | Bin 0 -> 179 bytes demos/shared/images/title_cap_right.png | Bin 0 -> 184 bytes demos/shared/images/title_stretch.png | Bin 0 -> 106 bytes demos/shared/shared.pri | 21 + demos/shared/shared.pro | 38 ++ demos/shared/shared.qrc | 39 ++ 48 files changed, 1714 insertions(+) create mode 100644 demos/shared/arthurstyle.cpp create mode 100644 demos/shared/arthurstyle.h create mode 100644 demos/shared/arthurwidgets.cpp create mode 100644 demos/shared/arthurwidgets.h create mode 100644 demos/shared/hoverpoints.cpp create mode 100644 demos/shared/hoverpoints.h create mode 100644 demos/shared/images/bg_pattern.png create mode 100644 demos/shared/images/button_normal_cap_left.png create mode 100644 demos/shared/images/button_normal_cap_right.png create mode 100644 demos/shared/images/button_normal_stretch.png create mode 100644 demos/shared/images/button_pressed_cap_left.png create mode 100644 demos/shared/images/button_pressed_cap_right.png create mode 100644 demos/shared/images/button_pressed_stretch.png create mode 100644 demos/shared/images/curve_thing_edit-6.png create mode 100644 demos/shared/images/frame_bottom.png create mode 100644 demos/shared/images/frame_bottomleft.png create mode 100644 demos/shared/images/frame_bottomright.png create mode 100644 demos/shared/images/frame_left.png create mode 100644 demos/shared/images/frame_right.png create mode 100644 demos/shared/images/frame_top.png create mode 100644 demos/shared/images/frame_topleft.png create mode 100644 demos/shared/images/frame_topright.png create mode 100644 demos/shared/images/groupframe_bottom_left.png create mode 100644 demos/shared/images/groupframe_bottom_right.png create mode 100644 demos/shared/images/groupframe_bottom_stretch.png create mode 100644 demos/shared/images/groupframe_left_stretch.png create mode 100644 demos/shared/images/groupframe_right_stretch.png create mode 100644 demos/shared/images/groupframe_top_stretch.png create mode 100644 demos/shared/images/groupframe_topleft.png create mode 100644 demos/shared/images/groupframe_topright.png create mode 100644 demos/shared/images/line_dash_dot.png create mode 100644 demos/shared/images/line_dash_dot_dot.png create mode 100644 demos/shared/images/line_dashed.png create mode 100644 demos/shared/images/line_dotted.png create mode 100644 demos/shared/images/line_solid.png create mode 100644 demos/shared/images/radiobutton-off.png create mode 100644 demos/shared/images/radiobutton-on.png create mode 100644 demos/shared/images/radiobutton_off.png create mode 100644 demos/shared/images/radiobutton_on.png create mode 100644 demos/shared/images/slider_bar.png create mode 100644 demos/shared/images/slider_thumb_off.png create mode 100644 demos/shared/images/slider_thumb_on.png create mode 100644 demos/shared/images/title_cap_left.png create mode 100644 demos/shared/images/title_cap_right.png create mode 100644 demos/shared/images/title_stretch.png create mode 100644 demos/shared/shared.pri create mode 100644 demos/shared/shared.pro create mode 100644 demos/shared/shared.qrc (limited to 'demos/shared') diff --git a/demos/shared/arthurstyle.cpp b/demos/shared/arthurstyle.cpp new file mode 100644 index 0000000000..e8e8a02017 --- /dev/null +++ b/demos/shared/arthurstyle.cpp @@ -0,0 +1,452 @@ +/**************************************************************************** +** +** 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$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "arthurstyle.h" +#include "arthurwidgets.h" +#include +#include +#include +#include +#include +#include +#include +#include + +QPixmap cached(const QString &img) +{ + if (QPixmap *p = QPixmapCache::find(img)) + return *p; + + QPixmap pm; + pm = QPixmap::fromImage(QImage(img), Qt::OrderedDither | Qt::OrderedAlphaDither); + if (pm.isNull()) + return QPixmap(); + + QPixmapCache::insert(img, pm); + return pm; +} + + +ArthurStyle::ArthurStyle() + : QWindowsStyle() +{ + Q_INIT_RESOURCE(shared); +} + + +void ArthurStyle::drawHoverRect(QPainter *painter, const QRect &r) const +{ + qreal h = r.height(); + qreal h2 = r.height() / qreal(2); + QPainterPath path; + path.addRect(r.x() + h2, r.y() + 0, r.width() - h2 * 2, r.height()); + path.addEllipse(r.x(), r.y(), h, h); + path.addEllipse(r.x() + r.width() - h, r.y(), h, h); + path.setFillRule(Qt::WindingFill); + painter->setPen(Qt::NoPen); + painter->setBrush(QColor(191, 215, 191)); + painter->setRenderHint(QPainter::Antialiasing); + painter->drawPath(path); +} + + +void ArthurStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, + QPainter *painter, const QWidget *widget) const +{ + + Q_ASSERT(option); + switch (element) { + case PE_FrameFocusRect: + break; + + case PE_IndicatorRadioButton: + if (const QStyleOptionButton *button = qstyleoption_cast(option)) { + bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver); + painter->save(); + QPixmap radio; + if (hover) + drawHoverRect(painter, widget->rect()); + + if (button->state & State_Sunken) + radio = cached(":res/images/radiobutton-on.png"); + else if (button->state & State_On) + radio = cached(":res/images/radiobutton_on.png"); + else + radio = cached(":res/images/radiobutton_off.png"); + painter->drawPixmap(button->rect.topLeft(), radio); + + painter->restore(); + } + break; + + case PE_PanelButtonCommand: + if (const QStyleOptionButton *button = qstyleoption_cast(option)) { + bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver); + + painter->save(); + const QPushButton *pushButton = qobject_cast(widget); + Q_ASSERT(pushButton); + QWidget *parent = pushButton->parentWidget(); + if (parent && qobject_cast(parent)) { + QLinearGradient lg(0, 0, 0, parent->height()); + lg.setColorAt(0, QColor(224,224,224)); + lg.setColorAt(1, QColor(255,255,255)); + painter->setPen(Qt::NoPen); + painter->setBrush(lg); + painter->setBrushOrigin(-widget->mapToParent(QPoint(0,0))); + painter->drawRect(button->rect); + painter->setBrushOrigin(0,0); + } + + bool down = (button->state & State_Sunken) || (button->state & State_On); + + QPixmap left, right, mid; + if (down) { + left = cached(":res/images/button_pressed_cap_left.png"); + right = cached(":res/images/button_pressed_cap_right.png"); + mid = cached(":res/images/button_pressed_stretch.png"); + } else { + left = cached(":res/images/button_normal_cap_left.png"); + right = cached(":res/images/button_normal_cap_right.png"); + mid = cached(":res/images/button_normal_stretch.png"); + } + painter->drawPixmap(button->rect.topLeft(), left); + painter->drawTiledPixmap(QRect(button->rect.x() + left.width(), + button->rect.y(), + button->rect.width() - left.width() - right.width(), + left.height()), + mid); + painter->drawPixmap(button->rect.x() + button->rect.width() - right.width(), + button->rect.y(), + right); + if (hover) + painter->fillRect(widget->rect().adjusted(3,5,-3,-5), QColor(31,127,31,63)); + painter->restore(); + } + break; + + case PE_FrameGroupBox: + if (const QStyleOptionFrameV2 *group + = qstyleoption_cast(option)) { + const QRect &r = group->rect; + + painter->save(); + int radius = 14; + int radius2 = radius*2; + QPainterPath clipPath; + clipPath.moveTo(radius, 0); + clipPath.arcTo(r.right() - radius2, 0, radius2, radius2, 90, -90); + clipPath.arcTo(r.right() - radius2, r.bottom() - radius2, radius2, radius2, 0, -90); + clipPath.arcTo(r.left(), r.bottom() - radius2, radius2, radius2, 270, -90); + clipPath.arcTo(r.left(), r.top(), radius2, radius2, 180, -90); + painter->setClipPath(clipPath); + QPixmap titleStretch = cached(":res/images/title_stretch.png"); + QPixmap topLeft = cached(":res/images/groupframe_topleft.png"); + QPixmap topRight = cached(":res/images/groupframe_topright.png"); + QPixmap bottomLeft = cached(":res/images/groupframe_bottom_left.png"); + QPixmap bottomRight = cached(":res/images/groupframe_bottom_right.png"); + QPixmap leftStretch = cached(":res/images/groupframe_left_stretch.png"); + QPixmap topStretch = cached(":res/images/groupframe_top_stretch.png"); + QPixmap rightStretch = cached(":res/images/groupframe_right_stretch.png"); + QPixmap bottomStretch = cached(":res/images/groupframe_bottom_stretch.png"); + QLinearGradient lg(0, 0, 0, r.height()); + lg.setColorAt(0, QColor(224,224,224)); + lg.setColorAt(1, QColor(255,255,255)); + painter->setPen(Qt::NoPen); + painter->setBrush(lg); + painter->drawRect(r.adjusted(0, titleStretch.height()/2, 0, 0)); + painter->setClipping(false); + + int topFrameOffset = titleStretch.height()/2 - 2; + painter->drawPixmap(r.topLeft() + QPoint(0, topFrameOffset), topLeft); + painter->drawPixmap(r.topRight() - QPoint(topRight.width()-1, 0) + + QPoint(0, topFrameOffset), topRight); + painter->drawPixmap(r.bottomLeft() - QPoint(0, bottomLeft.height()-1), bottomLeft); + painter->drawPixmap(r.bottomRight() - QPoint(bottomRight.width()-1, + bottomRight.height()-1), bottomRight); + + QRect left = r; + left.setY(r.y() + topLeft.height() + topFrameOffset); + left.setWidth(leftStretch.width()); + left.setHeight(r.height() - topLeft.height() - bottomLeft.height() - topFrameOffset); + painter->drawTiledPixmap(left, leftStretch); + + QRect top = r; + top.setX(r.x() + topLeft.width()); + top.setY(r.y() + topFrameOffset); + top.setWidth(r.width() - topLeft.width() - topRight.width()); + top.setHeight(topLeft.height()); + painter->drawTiledPixmap(top, topStretch); + + QRect right = r; + right.setX(r.right() - rightStretch.width()+1); + right.setY(r.y() + topRight.height() + topFrameOffset); + right.setWidth(rightStretch.width()); + right.setHeight(r.height() - topRight.height() + - bottomRight.height() - topFrameOffset); + painter->drawTiledPixmap(right, rightStretch); + + QRect bottom = r; + bottom.setX(r.x() + bottomLeft.width()); + bottom.setY(r.bottom() - bottomStretch.height()+1); + bottom.setWidth(r.width() - bottomLeft.width() - bottomRight.width()); + bottom.setHeight(bottomLeft.height()); + painter->drawTiledPixmap(bottom, bottomStretch); + painter->restore(); + } + break; + + default: + QWindowsStyle::drawPrimitive(element, option, painter, widget); + break; + } + return; +} + + +void ArthurStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, + QPainter *painter, const QWidget *widget) const +{ + switch (control) { + case CC_Slider: + if (const QStyleOptionSlider *slider = qstyleoption_cast(option)) { + QRect groove = subControlRect(CC_Slider, option, SC_SliderGroove, widget); + QRect handle = subControlRect(CC_Slider, option, SC_SliderHandle, widget); + + painter->save(); + + bool hover = (slider->state & State_Enabled) && (slider->state & State_MouseOver); + if (hover) { + QRect moderated = widget->rect().adjusted(0, 4, 0, -4); + drawHoverRect(painter, moderated); + } + + if ((option->subControls & SC_SliderGroove) && groove.isValid()) { + QPixmap grv = cached(":res/images/slider_bar.png"); + painter->drawPixmap(QRect(groove.x() + 5, groove.y(), + groove.width() - 10, grv.height()), + grv); + } + if ((option->subControls & SC_SliderHandle) && handle.isValid()) { + QPixmap hndl = cached(":res/images/slider_thumb_on.png"); + painter->drawPixmap(handle.topLeft(), hndl); + } + + painter->restore(); + } + break; + case CC_GroupBox: + if (const QStyleOptionGroupBox *groupBox + = qstyleoption_cast(option)) { + QStyleOptionGroupBox groupBoxCopy(*groupBox); + groupBoxCopy.subControls &= ~SC_GroupBoxLabel; + QWindowsStyle::drawComplexControl(control, &groupBoxCopy, painter, widget); + + if (groupBox->subControls & SC_GroupBoxLabel) { + const QRect &r = groupBox->rect; + QPixmap titleLeft = cached(":res/images/title_cap_left.png"); + QPixmap titleRight = cached(":res/images/title_cap_right.png"); + QPixmap titleStretch = cached(":res/images/title_stretch.png"); + int txt_width = groupBox->fontMetrics.width(groupBox->text) + 20; + painter->drawPixmap(r.center().x() - txt_width/2, 0, titleLeft); + QRect tileRect = subControlRect(control, groupBox, SC_GroupBoxLabel, widget); + painter->drawTiledPixmap(tileRect, titleStretch); + painter->drawPixmap(tileRect.x() + tileRect.width(), 0, titleRight); + int opacity = 31; + painter->setPen(QColor(0, 0, 0, opacity)); + painter->drawText(tileRect.translated(0, 1), + Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text); + painter->drawText(tileRect.translated(2, 1), + Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text); + painter->setPen(QColor(0, 0, 0, opacity * 2)); + painter->drawText(tileRect.translated(1, 1), + Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text); + painter->setPen(Qt::white); + painter->drawText(tileRect, Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text); + } + } + break; + default: + QWindowsStyle::drawComplexControl(control, option, painter, widget); + break; + } + return; +} + +QRect ArthurStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option, + SubControl subControl, const QWidget *widget) const +{ + QRect rect; + + switch (control) { + default: + rect = QWindowsStyle::subControlRect(control, option, subControl, widget); + break; + case CC_GroupBox: + if (const QStyleOptionGroupBox *group + = qstyleoption_cast(option)) { + switch (subControl) { + default: + rect = QWindowsStyle::subControlRect(control, option, subControl, widget); + break; + case SC_GroupBoxContents: + rect = QWindowsStyle::subControlRect(control, option, subControl, widget); + rect.adjust(0, -8, 0, 0); + break; + case SC_GroupBoxFrame: + rect = group->rect; + break; + case SC_GroupBoxLabel: + QPixmap titleLeft = cached(":res/images/title_cap_left.png"); + QPixmap titleRight = cached(":res/images/title_cap_right.png"); + QPixmap titleStretch = cached(":res/images/title_stretch.png"); + int txt_width = group->fontMetrics.width(group->text) + 20; + rect = QRect(group->rect.center().x() - txt_width/2 + titleLeft.width(), 0, + txt_width - titleLeft.width() - titleRight.width(), + titleStretch.height()); + break; + } + } + break; + } + + if (control == CC_Slider && subControl == SC_SliderHandle) { + rect.setWidth(13); + rect.setHeight(27); + } else if (control == CC_Slider && subControl == SC_SliderGroove) { + rect.setHeight(9); + rect.moveTop(27/2 - 9/2); + } + return rect; +} + +QSize ArthurStyle::sizeFromContents(ContentsType type, const QStyleOption *option, + const QSize &size, const QWidget *widget) const +{ + QSize newSize = QWindowsStyle::sizeFromContents(type, option, size, widget); + + + switch (type) { + case CT_RadioButton: + newSize += QSize(20, 0); + break; + + case CT_PushButton: + newSize.setHeight(26); + break; + + case CT_Slider: + newSize.setHeight(27); + break; + + default: + break; + } + + return newSize; +} + +int ArthurStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const +{ + if (pm == PM_SliderLength) + return 13; + return QWindowsStyle::pixelMetric(pm, opt, widget); +} + +void ArthurStyle::polish(QWidget *widget) +{ + if (widget->layout() && qobject_cast(widget)) { + if (widget->findChildren().size() == 0) { + widget->layout()->setSpacing(0); + widget->layout()->setMargin(12); + } else { + widget->layout()->setMargin(13); + } + } + + if (qobject_cast(widget) + || qobject_cast(widget) + || qobject_cast(widget)) { + widget->setAttribute(Qt::WA_Hover); + } + + QPalette pal = widget->palette(); + if (widget->isWindow()) { + pal.setColor(QPalette::Background, QColor(241, 241, 241)); + widget->setPalette(pal); + } + +} + +void ArthurStyle::unpolish(QWidget *widget) +{ + if (qobject_cast(widget) + || qobject_cast(widget) + || qobject_cast(widget)) { + widget->setAttribute(Qt::WA_Hover, false); + } +} + +void ArthurStyle::polish(QPalette &palette) +{ + palette.setColor(QPalette::Background, QColor(241, 241, 241)); +} + +QRect ArthurStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const +{ + QRect r; + switch(element) { + case SE_RadioButtonClickRect: + r = widget->rect(); + break; + case SE_RadioButtonContents: + r = widget->rect().adjusted(20, 0, 0, 0); + break; + default: + r = QWindowsStyle::subElementRect(element, option, widget); + break; + } + + if (qobject_cast(widget)) + r = r.adjusted(5, 0, -5, 0); + + return r; +} diff --git a/demos/shared/arthurstyle.h b/demos/shared/arthurstyle.h new file mode 100644 index 0000000000..9e3ada9b99 --- /dev/null +++ b/demos/shared/arthurstyle.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ARTHURSTYLE_H +#define ARTHURSTYLE_H + +#include + +QT_USE_NAMESPACE + +class ArthurStyle : public QWindowsStyle +{ +public: + ArthurStyle(); + + void drawHoverRect(QPainter *painter, const QRect &rect) const; + + void drawPrimitive(PrimitiveElement element, const QStyleOption *option, + QPainter *painter, const QWidget *widget = 0) const; +// void drawControl(ControlElement element, const QStyleOption *option, +// QPainter *painter, const QWidget *widget) const; + void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, + QPainter *painter, const QWidget *widget) const; + QSize sizeFromContents(ContentsType type, const QStyleOption *option, + const QSize &size, const QWidget *widget) const; + + QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const; + QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, + SubControl sc, const QWidget *widget) const; + +// SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option, +// const QPoint &pos, const QWidget *widget = 0) const; + + int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const; + + void polish(QPalette &palette); + void polish(QWidget *widget); + void unpolish(QWidget *widget); +}; + +#endif diff --git a/demos/shared/arthurwidgets.cpp b/demos/shared/arthurwidgets.cpp new file mode 100644 index 0000000000..d6b8ccabab --- /dev/null +++ b/demos/shared/arthurwidgets.cpp @@ -0,0 +1,371 @@ +/**************************************************************************** +** +** 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$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "arthurwidgets.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +extern QPixmap cached(const QString &img); + +ArthurFrame::ArthurFrame(QWidget *parent) + : QWidget(parent) + , m_prefer_image(false) +{ +#ifdef QT_OPENGL_SUPPORT + glw = 0; + m_use_opengl = false; + QGLFormat f = QGLFormat::defaultFormat(); + f.setSampleBuffers(true); + f.setStencil(true); + f.setAlpha(true); + f.setAlphaBufferSize(8); + QGLFormat::setDefaultFormat(f); +#endif + m_document = 0; + m_show_doc = false; + + m_tile = QPixmap(128, 128); + m_tile.fill(Qt::white); + QPainter pt(&m_tile); + QColor color(230, 230, 230); + pt.fillRect(0, 0, 64, 64, color); + pt.fillRect(64, 64, 64, 64, color); + pt.end(); + +// QPalette pal = palette(); +// pal.setBrush(backgroundRole(), m_tile); +// setPalette(pal); + +#ifdef Q_WS_X11 + QPixmap xRenderPixmap(1, 1); + m_prefer_image = xRenderPixmap.pixmapData()->classId() == QPixmapData::X11Class && !xRenderPixmap.x11PictureHandle(); +#endif +} + + +#ifdef QT_OPENGL_SUPPORT +void ArthurFrame::enableOpenGL(bool use_opengl) +{ + m_use_opengl = use_opengl; + + if (!glw) { + glw = new GLWidget(this); + glw->setAutoFillBackground(false); + glw->disableAutoBufferSwap(); + QApplication::postEvent(this, new QResizeEvent(size(), size())); + } + + if (use_opengl) { + glw->show(); + } else { + glw->hide(); + } + + update(); +} +#endif + +void ArthurFrame::paintEvent(QPaintEvent *e) +{ +#ifdef Q_WS_QWS + static QPixmap *static_image = 0; +#else + static QImage *static_image = 0; +#endif + QPainter painter; + if (preferImage() +#ifdef QT_OPENGL_SUPPORT + && !m_use_opengl +#endif + ) { + if (!static_image || static_image->size() != size()) { + delete static_image; +#ifdef Q_WS_QWS + static_image = new QPixmap(size()); +#else + static_image = new QImage(size(), QImage::Format_RGB32); +#endif + } + painter.begin(static_image); + + int o = 10; + + QBrush bg = palette().brush(QPalette::Background); + painter.fillRect(0, 0, o, o, bg); + painter.fillRect(width() - o, 0, o, o, bg); + painter.fillRect(0, height() - o, o, o, bg); + painter.fillRect(width() - o, height() - o, o, o, bg); + } else { +#ifdef QT_OPENGL_SUPPORT + if (m_use_opengl) { + painter.begin(glw); + painter.fillRect(QRectF(0, 0, glw->width(), glw->height()), palette().color(backgroundRole())); + } else { + painter.begin(this); + } +#else + painter.begin(this); +#endif + } + + painter.setClipRect(e->rect()); + + painter.setRenderHint(QPainter::Antialiasing); + + QPainterPath clipPath; + + QRect r = rect(); + qreal left = r.x() + 1; + qreal top = r.y() + 1; + qreal right = r.right(); + qreal bottom = r.bottom(); + qreal radius2 = 8 * 2; + + clipPath.moveTo(right - radius2, top); + clipPath.arcTo(right - radius2, top, radius2, radius2, 90, -90); + clipPath.arcTo(right - radius2, bottom - radius2, radius2, radius2, 0, -90); + clipPath.arcTo(left, bottom - radius2, radius2, radius2, 270, -90); + clipPath.arcTo(left, top, radius2, radius2, 180, -90); + clipPath.closeSubpath(); + + painter.save(); + painter.setClipPath(clipPath, Qt::IntersectClip); + + painter.drawTiledPixmap(rect(), m_tile); + + // client painting + + paint(&painter); + + painter.restore(); + + painter.save(); + if (m_show_doc) + paintDescription(&painter); + painter.restore(); + + int level = 180; + painter.setPen(QPen(QColor(level, level, level), 2)); + painter.setBrush(Qt::NoBrush); + painter.drawPath(clipPath); + + if (preferImage() +#ifdef QT_OPENGL_SUPPORT + && !m_use_opengl +#endif + ) { + painter.end(); + painter.begin(this); +#ifdef Q_WS_QWS + painter.drawPixmap(e->rect(), *static_image, e->rect()); +#else + painter.drawImage(e->rect(), *static_image, e->rect()); +#endif + } + +#ifdef QT_OPENGL_SUPPORT + if (m_use_opengl && (inherits("PathDeformRenderer") || inherits("PathStrokeRenderer") || inherits("CompositionRenderer") || m_show_doc)) + glw->swapBuffers(); +#endif +} + +void ArthurFrame::resizeEvent(QResizeEvent *e) +{ +#ifdef QT_OPENGL_SUPPORT + if (glw) + glw->setGeometry(0, 0, e->size().width()-1, e->size().height()-1); +#endif + QWidget::resizeEvent(e); +} + +void ArthurFrame::setDescriptionEnabled(bool enabled) +{ + if (m_show_doc != enabled) { + m_show_doc = enabled; + emit descriptionEnabledChanged(m_show_doc); + update(); + } +} + +void ArthurFrame::loadDescription(const QString &fileName) +{ + QFile textFile(fileName); + QString text; + if (!textFile.open(QFile::ReadOnly)) + text = QString("Unable to load resource file: '%1'").arg(fileName); + else + text = textFile.readAll(); + setDescription(text); +} + + +void ArthurFrame::setDescription(const QString &text) +{ + m_document = new QTextDocument(this); + m_document->setHtml(text); +} + +void ArthurFrame::paintDescription(QPainter *painter) +{ + if (!m_document) + return; + + int pageWidth = qMax(width() - 100, 100); + int pageHeight = qMax(height() - 100, 100); + if (pageWidth != m_document->pageSize().width()) { + m_document->setPageSize(QSize(pageWidth, pageHeight)); + } + + QRect textRect(width() / 2 - pageWidth / 2, + height() / 2 - pageHeight / 2, + pageWidth, + pageHeight); + int pad = 10; + QRect clearRect = textRect.adjusted(-pad, -pad, pad, pad); + painter->setPen(Qt::NoPen); + painter->setBrush(QColor(0, 0, 0, 63)); + int shade = 10; + painter->drawRect(clearRect.x() + clearRect.width() + 1, + clearRect.y() + shade, + shade, + clearRect.height() + 1); + painter->drawRect(clearRect.x() + shade, + clearRect.y() + clearRect.height() + 1, + clearRect.width() - shade + 1, + shade); + + painter->setRenderHint(QPainter::Antialiasing, false); + painter->setBrush(QColor(255, 255, 255, 220)); + painter->setPen(Qt::black); + painter->drawRect(clearRect); + + painter->setClipRegion(textRect, Qt::IntersectClip); + painter->translate(textRect.topLeft()); + + QAbstractTextDocumentLayout::PaintContext ctx; + + QLinearGradient g(0, 0, 0, textRect.height()); + g.setColorAt(0, Qt::black); + g.setColorAt(0.9, Qt::black); + g.setColorAt(1, Qt::transparent); + + QPalette pal = palette(); + pal.setBrush(QPalette::Text, g); + + ctx.palette = pal; + ctx.clip = QRect(0, 0, textRect.width(), textRect.height()); + m_document->documentLayout()->draw(painter, ctx); +} + +void ArthurFrame::loadSourceFile(const QString &sourceFile) +{ + m_sourceFileName = sourceFile; +} + +void ArthurFrame::showSource() +{ + // Check for existing source + if (findChild()) + return; + + QString contents; + if (m_sourceFileName.isEmpty()) { + contents = QString("No source for widget: '%1'").arg(objectName()); + } else { + QFile f(m_sourceFileName); + if (!f.open(QFile::ReadOnly)) + contents = QString("Could not open file: '%1'").arg(m_sourceFileName); + else + contents = f.readAll(); + } + + contents.replace('&', "&"); + contents.replace('<', "<"); + contents.replace('>', ">"); + + QStringList keywords; + keywords << "for " << "if " << "switch " << " int " << "#include " << "const" + << "void " << "uint " << "case " << "double " << "#define " << "static" + << "new" << "this"; + + foreach (QString keyword, keywords) + contents.replace(keyword, QLatin1String("") + keyword + QLatin1String("")); + contents.replace("(int ", "(int "); + + QStringList ppKeywords; + ppKeywords << "#ifdef" << "#ifndef" << "#if" << "#endif" << "#else"; + + foreach (QString keyword, ppKeywords) + contents.replace(keyword, QLatin1String("") + keyword + QLatin1String("")); + + contents.replace(QRegExp("(\\d\\d?)"), QLatin1String("\\1")); + + QRegExp commentRe("(//.+)\\n"); + commentRe.setMinimal(true); + contents.replace(commentRe, QLatin1String("\\1\n")); + + QRegExp stringLiteralRe("(\".+\")"); + stringLiteralRe.setMinimal(true); + contents.replace(stringLiteralRe, QLatin1String("\\1")); + + QString html = contents; + html.prepend("
");
+    html.append("
"); + + QTextBrowser *sourceViewer = new QTextBrowser(0); + sourceViewer->setWindowTitle("Source: " + m_sourceFileName.mid(5)); + sourceViewer->setParent(this, Qt::Dialog); + sourceViewer->setAttribute(Qt::WA_DeleteOnClose); + sourceViewer->setLineWrapMode(QTextEdit::NoWrap); + sourceViewer->setHtml(html); + sourceViewer->resize(600, 600); + sourceViewer->show(); +} diff --git a/demos/shared/arthurwidgets.h b/demos/shared/arthurwidgets.h new file mode 100644 index 0000000000..67571119f8 --- /dev/null +++ b/demos/shared/arthurwidgets.h @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** 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$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ARTHURWIDGETS_H +#define ARTHURWIDGETS_H + +#include "arthurstyle.h" +#include +#include +#include + +#if defined(QT_OPENGL_SUPPORT) +#include +#include +class GLWidget : public QGLWidget +{ +public: + GLWidget(QWidget *parent) + : QGLWidget(QGLFormat(QGL::SampleBuffers), parent) + { + setAttribute(Qt::WA_AcceptTouchEvents); + } + void disableAutoBufferSwap() { setAutoBufferSwap(false); } + void paintEvent(QPaintEvent *) { parentWidget()->update(); } +protected: + bool event(QEvent *event) + { + switch (event->type()) { + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + event->ignore(); + return false; + break; + default: + break; + } + return QGLWidget::event(event); + } +}; +#endif + +QT_FORWARD_DECLARE_CLASS(QTextDocument) +QT_FORWARD_DECLARE_CLASS(QTextEdit) +QT_FORWARD_DECLARE_CLASS(QVBoxLayout) + +class ArthurFrame : public QWidget +{ + Q_OBJECT +public: + ArthurFrame(QWidget *parent); + virtual void paint(QPainter *) {} + + + void paintDescription(QPainter *p); + + void loadDescription(const QString &filename); + void setDescription(const QString &htmlDesc); + + void loadSourceFile(const QString &fileName); + + bool preferImage() const { return m_prefer_image; } + +#if defined(QT_OPENGL_SUPPORT) + QGLWidget *glWidget() const { return glw; } +#endif + +public slots: + void setPreferImage(bool pi) { m_prefer_image = pi; } + void setDescriptionEnabled(bool enabled); + void showSource(); + +#if defined(QT_OPENGL_SUPPORT) + void enableOpenGL(bool use_opengl); + bool usesOpenGL() { return m_use_opengl; } +#endif + +signals: + void descriptionEnabledChanged(bool); + +protected: + void paintEvent(QPaintEvent *); + void resizeEvent(QResizeEvent *); + +#if defined(QT_OPENGL_SUPPORT) + GLWidget *glw; + bool m_use_opengl; +#endif + QPixmap m_tile; + + bool m_show_doc; + bool m_prefer_image; + QTextDocument *m_document; + + QString m_sourceFileName; + +}; + +#endif diff --git a/demos/shared/hoverpoints.cpp b/demos/shared/hoverpoints.cpp new file mode 100644 index 0000000000..272f89540c --- /dev/null +++ b/demos/shared/hoverpoints.cpp @@ -0,0 +1,415 @@ +/**************************************************************************** +** +** 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$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifdef QT_OPENGL_SUPPORT +#include +#endif + +#include "arthurwidgets.h" +#include "hoverpoints.h" + +#define printf + +HoverPoints::HoverPoints(QWidget *widget, PointShape shape) + : QObject(widget) +{ + m_widget = widget; + widget->installEventFilter(this); + widget->setAttribute(Qt::WA_AcceptTouchEvents); + + m_connectionType = CurveConnection; + m_sortType = NoSort; + m_shape = shape; + m_pointPen = QPen(QColor(255, 255, 255, 191), 1); + m_connectionPen = QPen(QColor(255, 255, 255, 127), 2); + m_pointBrush = QBrush(QColor(191, 191, 191, 127)); + m_pointSize = QSize(11, 11); + m_currentIndex = -1; + m_editable = true; + m_enabled = true; + + connect(this, SIGNAL(pointsChanged(QPolygonF)), + m_widget, SLOT(update())); +} + + +void HoverPoints::setEnabled(bool enabled) +{ + if (m_enabled != enabled) { + m_enabled = enabled; + m_widget->update(); + } +} + + +bool HoverPoints::eventFilter(QObject *object, QEvent *event) +{ + if (object == m_widget && m_enabled) { + switch (event->type()) { + + case QEvent::MouseButtonPress: + { + if (!m_fingerPointMapping.isEmpty()) + return true; + QMouseEvent *me = (QMouseEvent *) event; + + QPointF clickPos = me->pos(); + int index = -1; + for (int i=0; ibutton() == Qt::LeftButton) { + if (index == -1) { + if (!m_editable) + return false; + int pos = 0; + // Insert sort for x or y + if (m_sortType == XSort) { + for (int i=0; i clickPos.x()) { + pos = i; + break; + } + } else if (m_sortType == YSort) { + for (int i=0; i clickPos.y()) { + pos = i; + break; + } + } + + m_points.insert(pos, clickPos); + m_locks.insert(pos, 0); + m_currentIndex = pos; + firePointChange(); + } else { + m_currentIndex = index; + } + return true; + + } else if (me->button() == Qt::RightButton) { + if (index >= 0 && m_editable) { + if (m_locks[index] == 0) { + m_locks.remove(index); + m_points.remove(index); + } + firePointChange(); + return true; + } + } + + } + break; + + case QEvent::MouseButtonRelease: + if (!m_fingerPointMapping.isEmpty()) + return true; + m_currentIndex = -1; + break; + + case QEvent::MouseMove: + if (!m_fingerPointMapping.isEmpty()) + return true; + if (m_currentIndex >= 0) + movePoint(m_currentIndex, ((QMouseEvent *)event)->pos()); + break; + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + { + const QTouchEvent *const touchEvent = static_cast(event); + const QList points = touchEvent->touchPoints(); + const qreal pointSize = qMax(m_pointSize.width(), m_pointSize.height()); + foreach (const QTouchEvent::TouchPoint &touchPoint, points) { + const int id = touchPoint.id(); + switch (touchPoint.state()) { + case Qt::TouchPointPressed: + { + // find the point, move it + QSet activePoints = QSet::fromList(m_fingerPointMapping.values()); + int activePoint = -1; + qreal distance = -1; + const int pointsCount = m_points.size(); + const int activePointCount = activePoints.size(); + if (pointsCount == 2 && activePointCount == 1) { // only two points + activePoint = activePoints.contains(0) ? 1 : 0; + } else { + for (int i=0; i::iterator it = m_fingerPointMapping.find(id); + movePoint(it.value(), touchPoint.pos()); + m_fingerPointMapping.erase(it); + } + break; + case Qt::TouchPointMoved: + { + // move the point + const int pointIdx = m_fingerPointMapping.value(id, -1); + if (pointIdx >= 0) // do we track this point? + movePoint(pointIdx, touchPoint.pos()); + } + break; + default: + break; + } + } + if (m_fingerPointMapping.isEmpty()) { + event->ignore(); + return false; + } else { + return true; + } + } + break; + case QEvent::TouchEnd: + if (m_fingerPointMapping.isEmpty()) { + event->ignore(); + return false; + } + return true; + break; + + case QEvent::Resize: + { + QResizeEvent *e = (QResizeEvent *) event; + if (e->oldSize().width() == 0 || e->oldSize().height() == 0) + break; + qreal stretch_x = e->size().width() / qreal(e->oldSize().width()); + qreal stretch_y = e->size().height() / qreal(e->oldSize().height()); + for (int i=0; i(that_widget); + if (af && af->usesOpenGL()) + af->glWidget()->swapBuffers(); +#endif + return true; + } + default: + break; + } + } + + return false; +} + + +void HoverPoints::paintPoints() +{ + QPainter p; +#ifdef QT_OPENGL_SUPPORT + ArthurFrame *af = qobject_cast(m_widget); + if (af && af->usesOpenGL()) + p.begin(af->glWidget()); + else + p.begin(m_widget); +#else + p.begin(m_widget); +#endif + + p.setRenderHint(QPainter::Antialiasing); + + if (m_connectionPen.style() != Qt::NoPen && m_connectionType != NoConnection) { + p.setPen(m_connectionPen); + + if (m_connectionType == CurveConnection) { + QPainterPath path; + path.moveTo(m_points.at(0)); + for (int i=1; i right || (lock & HoverPoints::LockToRight)) p.setX(right); + + if (p.y() < top || (lock & HoverPoints::LockToTop)) p.setY(top); + else if (p.y() > bottom || (lock & HoverPoints::LockToBottom)) p.setY(bottom); + + return p; +} + +void HoverPoints::setPoints(const QPolygonF &points) +{ + if (points.size() != m_points.size()) + m_fingerPointMapping.clear(); + m_points.clear(); + for (int i=0; i 0) { + m_locks.resize(m_points.size()); + + m_locks.fill(0); + } +} + + +void HoverPoints::movePoint(int index, const QPointF &point, bool emitUpdate) +{ + m_points[index] = bound_point(point, boundingRect(), m_locks.at(index)); + if (emitUpdate) + firePointChange(); +} + + +inline static bool x_less_than(const QPointF &p1, const QPointF &p2) +{ + return p1.x() < p2.x(); +} + + +inline static bool y_less_than(const QPointF &p1, const QPointF &p2) +{ + return p1.y() < p2.y(); +} + +void HoverPoints::firePointChange() +{ +// printf("HoverPoints::firePointChange(), current=%d\n", m_currentIndex); + + if (m_sortType != NoSort) { + + QPointF oldCurrent; + if (m_currentIndex != -1) { + oldCurrent = m_points[m_currentIndex]; + } + + if (m_sortType == XSort) + qSort(m_points.begin(), m_points.end(), x_less_than); + else if (m_sortType == YSort) + qSort(m_points.begin(), m_points.end(), y_less_than); + + // Compensate for changed order... + if (m_currentIndex != -1) { + for (int i=0; i + +QT_FORWARD_DECLARE_CLASS(QBypassWidget) + +class HoverPoints : public QObject +{ + Q_OBJECT +public: + enum PointShape { + CircleShape, + RectangleShape + }; + + enum LockType { + LockToLeft = 0x01, + LockToRight = 0x02, + LockToTop = 0x04, + LockToBottom = 0x08 + }; + + enum SortType { + NoSort, + XSort, + YSort + }; + + enum ConnectionType { + NoConnection, + LineConnection, + CurveConnection + }; + + HoverPoints(QWidget *widget, PointShape shape); + + bool eventFilter(QObject *object, QEvent *event); + + void paintPoints(); + + inline QRectF boundingRect() const; + void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; } + + QPolygonF points() const { return m_points; } + void setPoints(const QPolygonF &points); + + QSizeF pointSize() const { return m_pointSize; } + void setPointSize(const QSizeF &size) { m_pointSize = size; } + + SortType sortType() const { return m_sortType; } + void setSortType(SortType sortType) { m_sortType = sortType; } + + ConnectionType connectionType() const { return m_connectionType; } + void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; } + + void setConnectionPen(const QPen &pen) { m_connectionPen = pen; } + void setShapePen(const QPen &pen) { m_pointPen = pen; } + void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; } + + void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; } + + void setEditable(bool editable) { m_editable = editable; } + bool editable() const { return m_editable; } + +public slots: + void setEnabled(bool enabled); + void setDisabled(bool disabled) { setEnabled(!disabled); } + +signals: + void pointsChanged(const QPolygonF &points); + +public: + void firePointChange(); + +private: + inline QRectF pointBoundingRect(int i) const; + void movePoint(int i, const QPointF &newPos, bool emitChange = true); + + QWidget *m_widget; + + QPolygonF m_points; + QRectF m_bounds; + PointShape m_shape; + SortType m_sortType; + ConnectionType m_connectionType; + + QVector m_locks; + + QSizeF m_pointSize; + int m_currentIndex; + bool m_editable; + bool m_enabled; + + QHash m_fingerPointMapping; + + QPen m_pointPen; + QBrush m_pointBrush; + QPen m_connectionPen; +}; + + +inline QRectF HoverPoints::pointBoundingRect(int i) const +{ + QPointF p = m_points.at(i); + qreal w = m_pointSize.width(); + qreal h = m_pointSize.height(); + qreal x = p.x() - w / 2; + qreal y = p.y() - h / 2; + return QRectF(x, y, w, h); +} + +inline QRectF HoverPoints::boundingRect() const +{ + if (m_bounds.isEmpty()) + return m_widget->rect(); + else + return m_bounds; +} + +#endif // HOVERPOINTS_H diff --git a/demos/shared/images/bg_pattern.png b/demos/shared/images/bg_pattern.png new file mode 100644 index 0000000000..ee670266f0 Binary files /dev/null and b/demos/shared/images/bg_pattern.png differ diff --git a/demos/shared/images/button_normal_cap_left.png b/demos/shared/images/button_normal_cap_left.png new file mode 100644 index 0000000000..db31dd971d Binary files /dev/null and b/demos/shared/images/button_normal_cap_left.png differ diff --git a/demos/shared/images/button_normal_cap_right.png b/demos/shared/images/button_normal_cap_right.png new file mode 100644 index 0000000000..38ead1c719 Binary files /dev/null and b/demos/shared/images/button_normal_cap_right.png differ diff --git a/demos/shared/images/button_normal_stretch.png b/demos/shared/images/button_normal_stretch.png new file mode 100644 index 0000000000..87abe67ac9 Binary files /dev/null and b/demos/shared/images/button_normal_stretch.png differ diff --git a/demos/shared/images/button_pressed_cap_left.png b/demos/shared/images/button_pressed_cap_left.png new file mode 100644 index 0000000000..66bfc13cb4 Binary files /dev/null and b/demos/shared/images/button_pressed_cap_left.png differ diff --git a/demos/shared/images/button_pressed_cap_right.png b/demos/shared/images/button_pressed_cap_right.png new file mode 100644 index 0000000000..3d4cfe25b1 Binary files /dev/null and b/demos/shared/images/button_pressed_cap_right.png differ diff --git a/demos/shared/images/button_pressed_stretch.png b/demos/shared/images/button_pressed_stretch.png new file mode 100644 index 0000000000..4dd4ad11e6 Binary files /dev/null and b/demos/shared/images/button_pressed_stretch.png differ diff --git a/demos/shared/images/curve_thing_edit-6.png b/demos/shared/images/curve_thing_edit-6.png new file mode 100644 index 0000000000..034b474d02 Binary files /dev/null and b/demos/shared/images/curve_thing_edit-6.png differ diff --git a/demos/shared/images/frame_bottom.png b/demos/shared/images/frame_bottom.png new file mode 100644 index 0000000000..889b40d304 Binary files /dev/null and b/demos/shared/images/frame_bottom.png differ diff --git a/demos/shared/images/frame_bottomleft.png b/demos/shared/images/frame_bottomleft.png new file mode 100644 index 0000000000..0b3023f397 Binary files /dev/null and b/demos/shared/images/frame_bottomleft.png differ diff --git a/demos/shared/images/frame_bottomright.png b/demos/shared/images/frame_bottomright.png new file mode 100644 index 0000000000..0021e35864 Binary files /dev/null and b/demos/shared/images/frame_bottomright.png differ diff --git a/demos/shared/images/frame_left.png b/demos/shared/images/frame_left.png new file mode 100644 index 0000000000..40f331c293 Binary files /dev/null and b/demos/shared/images/frame_left.png differ diff --git a/demos/shared/images/frame_right.png b/demos/shared/images/frame_right.png new file mode 100644 index 0000000000..023af8c700 Binary files /dev/null and b/demos/shared/images/frame_right.png differ diff --git a/demos/shared/images/frame_top.png b/demos/shared/images/frame_top.png new file mode 100644 index 0000000000..001f3a7144 Binary files /dev/null and b/demos/shared/images/frame_top.png differ diff --git a/demos/shared/images/frame_topleft.png b/demos/shared/images/frame_topleft.png new file mode 100644 index 0000000000..58c68d407a Binary files /dev/null and b/demos/shared/images/frame_topleft.png differ diff --git a/demos/shared/images/frame_topright.png b/demos/shared/images/frame_topright.png new file mode 100644 index 0000000000..6a7e8d3eb3 Binary files /dev/null and b/demos/shared/images/frame_topright.png differ diff --git a/demos/shared/images/groupframe_bottom_left.png b/demos/shared/images/groupframe_bottom_left.png new file mode 100644 index 0000000000..af2fe061e3 Binary files /dev/null and b/demos/shared/images/groupframe_bottom_left.png differ diff --git a/demos/shared/images/groupframe_bottom_right.png b/demos/shared/images/groupframe_bottom_right.png new file mode 100644 index 0000000000..fdf2e97b13 Binary files /dev/null and b/demos/shared/images/groupframe_bottom_right.png differ diff --git a/demos/shared/images/groupframe_bottom_stretch.png b/demos/shared/images/groupframe_bottom_stretch.png new file mode 100644 index 0000000000..f47b67d7c0 Binary files /dev/null and b/demos/shared/images/groupframe_bottom_stretch.png differ diff --git a/demos/shared/images/groupframe_left_stretch.png b/demos/shared/images/groupframe_left_stretch.png new file mode 100644 index 0000000000..c122f462ed Binary files /dev/null and b/demos/shared/images/groupframe_left_stretch.png differ diff --git a/demos/shared/images/groupframe_right_stretch.png b/demos/shared/images/groupframe_right_stretch.png new file mode 100644 index 0000000000..1056b7812a Binary files /dev/null and b/demos/shared/images/groupframe_right_stretch.png differ diff --git a/demos/shared/images/groupframe_top_stretch.png b/demos/shared/images/groupframe_top_stretch.png new file mode 100644 index 0000000000..5746ef96fc Binary files /dev/null and b/demos/shared/images/groupframe_top_stretch.png differ diff --git a/demos/shared/images/groupframe_topleft.png b/demos/shared/images/groupframe_topleft.png new file mode 100644 index 0000000000..98d9cd96b4 Binary files /dev/null and b/demos/shared/images/groupframe_topleft.png differ diff --git a/demos/shared/images/groupframe_topright.png b/demos/shared/images/groupframe_topright.png new file mode 100644 index 0000000000..1a0a328c20 Binary files /dev/null and b/demos/shared/images/groupframe_topright.png differ diff --git a/demos/shared/images/line_dash_dot.png b/demos/shared/images/line_dash_dot.png new file mode 100644 index 0000000000..1c61442d9f Binary files /dev/null and b/demos/shared/images/line_dash_dot.png differ diff --git a/demos/shared/images/line_dash_dot_dot.png b/demos/shared/images/line_dash_dot_dot.png new file mode 100644 index 0000000000..0d9bb972f9 Binary files /dev/null and b/demos/shared/images/line_dash_dot_dot.png differ diff --git a/demos/shared/images/line_dashed.png b/demos/shared/images/line_dashed.png new file mode 100644 index 0000000000..d5bc7ea5fe Binary files /dev/null and b/demos/shared/images/line_dashed.png differ diff --git a/demos/shared/images/line_dotted.png b/demos/shared/images/line_dotted.png new file mode 100644 index 0000000000..a2f9a35925 Binary files /dev/null and b/demos/shared/images/line_dotted.png differ diff --git a/demos/shared/images/line_solid.png b/demos/shared/images/line_solid.png new file mode 100644 index 0000000000..60ef3f9485 Binary files /dev/null and b/demos/shared/images/line_solid.png differ diff --git a/demos/shared/images/radiobutton-off.png b/demos/shared/images/radiobutton-off.png new file mode 100644 index 0000000000..af1753a3e7 Binary files /dev/null and b/demos/shared/images/radiobutton-off.png differ diff --git a/demos/shared/images/radiobutton-on.png b/demos/shared/images/radiobutton-on.png new file mode 100644 index 0000000000..f875838bb5 Binary files /dev/null and b/demos/shared/images/radiobutton-on.png differ diff --git a/demos/shared/images/radiobutton_off.png b/demos/shared/images/radiobutton_off.png new file mode 100644 index 0000000000..400906ebfa Binary files /dev/null and b/demos/shared/images/radiobutton_off.png differ diff --git a/demos/shared/images/radiobutton_on.png b/demos/shared/images/radiobutton_on.png new file mode 100644 index 0000000000..50a049ec56 Binary files /dev/null and b/demos/shared/images/radiobutton_on.png differ diff --git a/demos/shared/images/slider_bar.png b/demos/shared/images/slider_bar.png new file mode 100644 index 0000000000..1b3d62c007 Binary files /dev/null and b/demos/shared/images/slider_bar.png differ diff --git a/demos/shared/images/slider_thumb_off.png b/demos/shared/images/slider_thumb_off.png new file mode 100644 index 0000000000..d7f141daef Binary files /dev/null and b/demos/shared/images/slider_thumb_off.png differ diff --git a/demos/shared/images/slider_thumb_on.png b/demos/shared/images/slider_thumb_on.png new file mode 100644 index 0000000000..8e1f510813 Binary files /dev/null and b/demos/shared/images/slider_thumb_on.png differ diff --git a/demos/shared/images/title_cap_left.png b/demos/shared/images/title_cap_left.png new file mode 100644 index 0000000000..2d475070c8 Binary files /dev/null and b/demos/shared/images/title_cap_left.png differ diff --git a/demos/shared/images/title_cap_right.png b/demos/shared/images/title_cap_right.png new file mode 100644 index 0000000000..dc3ff8536c Binary files /dev/null and b/demos/shared/images/title_cap_right.png differ diff --git a/demos/shared/images/title_stretch.png b/demos/shared/images/title_stretch.png new file mode 100644 index 0000000000..11043345d0 Binary files /dev/null and b/demos/shared/images/title_stretch.png differ diff --git a/demos/shared/shared.pri b/demos/shared/shared.pri new file mode 100644 index 0000000000..fb7b04c0be --- /dev/null +++ b/demos/shared/shared.pri @@ -0,0 +1,21 @@ +INCLUDEPATH += $$SHARED_FOLDER + +build_all:!build_pass { + CONFIG -= build_all + CONFIG += release +} +contains(CONFIG, debug_and_release_target) { + CONFIG(debug, debug|release) { + QMAKE_LIBDIR += $$SHARED_FOLDER/debug + } else { + QMAKE_LIBDIR += $$SHARED_FOLDER/release + } +} else { + QMAKE_LIBDIR += $$SHARED_FOLDER +} + +hpux-acc*:LIBS += $$SHARED_FOLDER/libdemo_shared.a +hpuxi-acc*:LIBS += $$SHARED_FOLDER/libdemo_shared.a +symbian:LIBS += -ldemo_shared.lib +!hpuxi-acc*:!hpux-acc*:!symbian:LIBS += -ldemo_shared + diff --git a/demos/shared/shared.pro b/demos/shared/shared.pro new file mode 100644 index 0000000000..4fc3809be0 --- /dev/null +++ b/demos/shared/shared.pro @@ -0,0 +1,38 @@ +TEMPLATE = lib +CONFIG += static + +contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles2) { + DEFINES += QT_OPENGL_SUPPORT + QT += opengl +} + +build_all:!build_pass { + CONFIG -= build_all + CONFIG += release +} +TARGET = demo_shared + +SOURCES += \ + arthurstyle.cpp\ + arthurwidgets.cpp \ + hoverpoints.cpp + +HEADERS += \ + arthurstyle.h \ + arthurwidgets.h \ + hoverpoints.h + +RESOURCES += shared.qrc + +# install +target.path = $$[QT_INSTALL_DEMOS]/qtbase/shared +sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.pri images +sources.path = $$[QT_INSTALL_DEMOS]/qtbase/shared +INSTALLS += sources + +!cross_compile:INSTALLS += target + +symbian { + TARGET.UID3 = 0xA000A63C + include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) +} diff --git a/demos/shared/shared.qrc b/demos/shared/shared.qrc new file mode 100644 index 0000000000..17336ecf80 --- /dev/null +++ b/demos/shared/shared.qrc @@ -0,0 +1,39 @@ + + + images/button_normal_cap_left.png + images/button_normal_cap_right.png + images/button_normal_stretch.png + images/button_pressed_cap_left.png + images/button_pressed_cap_right.png + images/button_pressed_stretch.png + images/radiobutton-on.png + images/radiobutton_on.png + images/radiobutton_off.png + images/slider_bar.png + images/slider_thumb_on.png + images/groupframe_topleft.png + images/groupframe_topright.png + images/groupframe_bottom_left.png + images/groupframe_bottom_right.png + images/groupframe_top_stretch.png + images/groupframe_bottom_stretch.png + images/groupframe_left_stretch.png + images/groupframe_right_stretch.png + images/frame_topleft.png + images/frame_topright.png + images/frame_bottomleft.png + images/frame_bottomright.png + images/frame_left.png + images/frame_top.png + images/frame_right.png + images/frame_bottom.png + images/title_cap_left.png + images/title_cap_right.png + images/title_stretch.png + images/line_dash_dot.png + images/line_dotted.png + images/line_dashed.png + images/line_solid.png + images/line_dash_dot_dot.png + + -- cgit v1.2.3