~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/designer/src/designer/versiondialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2005-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the designer application of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include <QtCore/QVector>
 
30
#include <QtGui/QMouseEvent>
 
31
#include <QtGui/QGridLayout>
 
32
#include <QtGui/QLabel>
 
33
#include <QtGui/QPushButton>
 
34
#include <QtGui/QPainter>
 
35
#include <QtGui/QPainterPath>
 
36
#include <QtGui/QStyleOption>
 
37
#include "versiondialog.h"
 
38
 
 
39
class VersionLabel : public QLabel
 
40
{
 
41
    Q_OBJECT
 
42
public:
 
43
    VersionLabel(QWidget *parent = 0);
 
44
 
 
45
signals:
 
46
    void triggered();
 
47
 
 
48
protected:
 
49
    void mousePressEvent(QMouseEvent *me);
 
50
    void mouseMoveEvent(QMouseEvent *me);
 
51
    void mouseReleaseEvent(QMouseEvent *me);
 
52
    void paintEvent(QPaintEvent *pe);
 
53
private:
 
54
    QVector<QPoint> hitPoints;
 
55
    QVector<QPoint> missPoints;
 
56
    QPainterPath m_path;
 
57
    bool secondStage;
 
58
    bool m_pushed;
 
59
};
 
60
 
 
61
VersionLabel::VersionLabel(QWidget *parent)
 
62
        : QLabel(parent), secondStage(false), m_pushed(false)
 
63
{
 
64
    setPixmap(QPixmap(":/trolltech/designer/images/designer.png"));
 
65
    hitPoints.append(QPoint(56, 25));
 
66
    hitPoints.append(QPoint(29, 55));
 
67
    hitPoints.append(QPoint(56, 87));
 
68
    hitPoints.append(QPoint(82, 55));
 
69
    hitPoints.append(QPoint(58, 56));
 
70
 
 
71
    secondStage = false;
 
72
    m_pushed = false;
 
73
}
 
74
 
 
75
void VersionLabel::mousePressEvent(QMouseEvent *me)
 
76
{
 
77
    if (me->button() == Qt::LeftButton) {
 
78
        if (!secondStage) {
 
79
            m_path = QPainterPath(me->pos());
 
80
        } else {
 
81
            m_pushed = true;
 
82
            update();
 
83
        }
 
84
    }
 
85
}
 
86
 
 
87
void VersionLabel::mouseMoveEvent(QMouseEvent *me)
 
88
{
 
89
    if (me->buttons() & Qt::LeftButton)
 
90
        if (!secondStage)
 
91
            m_path.lineTo(me->pos());
 
92
}
 
93
 
 
94
void VersionLabel::mouseReleaseEvent(QMouseEvent *me)
 
95
{
 
96
    if (me->button() == Qt::LeftButton) {
 
97
        if (!secondStage) {
 
98
            m_path.lineTo(me->pos());
 
99
            bool gotIt = true;
 
100
            QPoint pt;
 
101
            foreach(pt, hitPoints) {
 
102
                if (!m_path.contains(pt)) {
 
103
                    gotIt = false;
 
104
                    break;
 
105
                }
 
106
            }
 
107
            if (gotIt) {
 
108
                foreach(pt, missPoints) {
 
109
                    if (m_path.contains(pt)) {
 
110
                        gotIt = false;
 
111
                        break;
 
112
                    }
 
113
                }
 
114
            }
 
115
            if (gotIt && !secondStage) {
 
116
                secondStage = true;
 
117
                m_path = QPainterPath();
 
118
                update();
 
119
            }
 
120
        } else {
 
121
            m_pushed = false;
 
122
            update();
 
123
            emit triggered();
 
124
        }
 
125
    }
 
126
}
 
127
 
 
128
void VersionLabel::paintEvent(QPaintEvent *pe)
 
129
{
 
130
    if (secondStage) {
 
131
        QPainter p(this);
 
132
        QStyleOptionButton opt;
 
133
        opt.init(this);
 
134
        if (!m_pushed)
 
135
            opt.state |= QStyle::State_Raised;
 
136
        else
 
137
            opt.state |= QStyle::State_Sunken;
 
138
        opt.state &= ~QStyle::State_HasFocus;
 
139
        style()->drawControl(QStyle::CE_PushButtonBevel, &opt, &p, this);
 
140
    }
 
141
    QLabel::paintEvent(pe);
 
142
}
 
143
 
 
144
VersionDialog::VersionDialog(QWidget *parent)
 
145
    : QDialog(parent
 
146
#ifdef Q_WS_MAC
 
147
            , Qt::Tool
 
148
#endif
 
149
            )
 
150
{
 
151
    QGridLayout *layout = new QGridLayout(this);
 
152
    VersionLabel *label = new VersionLabel(this);
 
153
    QLabel *lbl = new QLabel(this);
 
154
    lbl->setText(tr("<h3>%1</h3>"
 
155
                    "<br/><br/>Version %2"
 
156
#if defined(QT_OPENSOURCE)
 
157
                    " Open Source Edition"
 
158
#endif
 
159
                    "<br/>Qt Designer is a graphical user interface designer "
 
160
                    "for Qt applications.<br/><br/>"
 
161
#if defined(QT_OPENSOURCE)
 
162
                    "This version of Qt Designer is part of the Qt Open Source Edition, for use "
 
163
                    "in the development of Open Source applications. "
 
164
                    "Qt is a comprehensive C++ framework for cross-platform application "
 
165
                    "development.<br/><br/>"
 
166
                    "You need a commercial Qt license for development of proprietary (closed "
 
167
                    "source) applications. Please see <tt>http://www.trolltech.com/company/model"
 
168
                    ".html</tt> for an overview of Qt licensing.<br/>"
 
169
#else
 
170
                    "This program is licensed to you under the terms of the "
 
171
                    "Qt Commercial License Agreement. For details, see the file LICENSE "
 
172
                    "that came with this software distribution.<br/>"
 
173
#endif
 
174
                    "<br/>Copyright 2000-2005 Trolltech AS. All rights reserved."
 
175
                    "<br/><br/>The program is provided AS IS with NO WARRANTY OF ANY KIND,"
 
176
                    " INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A"
 
177
                    " PARTICULAR PURPOSE.<br/> ").arg(tr("Qt Designer"))
 
178
                    .arg(QLatin1String(QT_VERSION_STR)));
 
179
    lbl->setWordWrap(true);
 
180
    QPushButton *cmd = new QPushButton("OK", this);
 
181
    cmd->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
 
182
    cmd->setDefault(true);
 
183
    connect(cmd, SIGNAL(clicked()), this, SLOT(reject()));
 
184
    connect(label, SIGNAL(triggered()), this, SLOT(accept()));
 
185
    layout->addWidget(label, 0, 0, 1, 1);
 
186
    layout->addWidget(lbl, 0, 1, 4, 4);
 
187
    layout->addWidget(cmd, 4, 2, 1, 1);
 
188
}
 
189
 
 
190
VersionDialog::~VersionDialog()
 
191
{
 
192
}
 
193
 
 
194
#include "versiondialog.moc"