annotate examples/desktop/systray/window.d @ 282:256ab6cb8e85

Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
author eldar
date Fri, 16 Oct 2009 02:43:59 +0000
parents 2c9ef955a171
children 7a3c43424dca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
120
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
1 /****************************************************************************
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
2 **
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
4 ** Contact: Qt Software Information (qt-info@nokia.com)
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
5 **
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
6 ** This file is part of the examples of the Qt Toolkit.
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
7 **
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
8 ** $QT_BEGIN_LICENSE:LGPL$
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
9 ** Commercial Usage
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
10 ** Licensees holding valid Qt Commercial licenses may use this file in
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
11 ** accordance with the Qt Commercial License Agreement provided with the
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
12 ** Software or, alternatively, in accordance with the terms contained in
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
13 ** a written agreement between you and Nokia.
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
14 **
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
15 ** GNU Lesser General Public License Usage
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
17 ** General Public License version 2.1 as published by the Free Software
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
19 ** packaging of this file. Please review the following information to
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
22 **
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
23 ** In addition, as a special exception, Nokia gives you certain
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
24 ** additional rights. These rights are described in the Nokia Qt LGPL
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
26 ** package.
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
27 **
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
28 ** GNU General Public License Usage
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
29 ** Alternatively, this file may be used under the terms of the GNU
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
30 ** General Public License version 3.0 as published by the Free Software
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
31 ** Foundation and appearing in the file LICENSE.GPL included in the
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
32 ** packaging of this file. Please review the following information to
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
33 ** ensure the GNU General Public License version 3.0 requirements will be
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
34 ** met: http://www.gnu.org/copyleft/gpl.html.
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
35 **
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
36 ** If you are unsure which license is appropriate for your use, please
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
37 ** contact the sales department at qt-sales@nokia.com.
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
38 ** $QT_END_LICENSE$
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
39 **
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
40 ****************************************************************************/
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
41 module window;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
42
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
43 import qt.gui.QSystemTrayIcon;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
44 import qt.gui.QDialog;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
45 import qt.gui.QAction;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
46 import qt.gui.QCheckBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
47 import qt.gui.QComboBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
48 import qt.gui.QGroupBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
49 import qt.gui.QLabel;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
50 import qt.gui.QLineEdit;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
51 import qt.gui.QMenu;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
52 import qt.gui.QPushButton;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
53 import qt.gui.QSpinBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
54 import qt.gui.QTextEdit;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
55 import qt.gui.QVBoxLayout;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
56 import qt.gui.QHBoxLayout;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
57 import qt.gui.QMessageBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
58 import qt.gui.QGridLayout;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
59
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
60
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
61 class Window : public QDialog
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
62 {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
63 public:
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
64
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
65 this()
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
66 {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
67 createIconGroupBox();
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
68 createMessageGroupBox();
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
69
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
70 iconLabel.setMinimumWidth(durationLabel.sizeHint().width());
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
71
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
72 createActions();
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
73 createTrayIcon();
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
74
282
256ab6cb8e85 Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents: 120
diff changeset
75 connect!("clicked")(showMessageButton, &this.showMessage);
256ab6cb8e85 Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents: 120
diff changeset
76 connect!("toggled")(showIconCheckBox, &trayIcon.setVisible);
256ab6cb8e85 Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents: 120
diff changeset
77 connect!("currentIndexChanged")(iconComboBox, &this.setIcon);
256ab6cb8e85 Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents: 120
diff changeset
78 connect!("messageClicked")(trayIcon, &this.messageClicked);
256ab6cb8e85 Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents: 120
diff changeset
79 connect!("activated")(trayIcon, &this.iconActivated);
120
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
80
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
81 QVBoxLayout mainLayout = new QVBoxLayout;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
82 mainLayout.addWidget(iconGroupBox);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
83 mainLayout.addWidget(messageGroupBox);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
84 setLayout(mainLayout);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
85
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
86 iconComboBox.setCurrentIndex(1);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
87 trayIcon.show();
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
88
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
89 setWindowTitle(tr("Systray"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
90 resize(400, 300);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
91 }
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
92
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
93 void setVisible(bool visible)
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
94 {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
95 minimizeAction.setEnabled(visible);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
96 maximizeAction.setEnabled(!isMaximized());
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
97 restoreAction.setEnabled(isMaximized() || !visible);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
98 QDialog.setVisible(visible);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
99 }
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
100
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
101 protected:
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
102
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
103 void closeEvent(QCloseEvent event)
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
104 {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
105 if (trayIcon.isVisible()) {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
106 QMessageBox.information(this, tr("Systray"),
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
107 tr("The program will keep running in the system tray. To terminate the program, "
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
108 "choose <b>Quit</b> in the context menu of the system tray entry."));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
109 hide();
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
110 event.ignore();
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
111 }
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
112 }
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
113
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
114 private:
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
115
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
116 void setIcon(int index)
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
117 {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
118 QIcon icon = iconComboBox.itemIcon(index);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
119 trayIcon.setIcon(icon);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
120 setWindowIcon(icon);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
121
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
122 trayIcon.setToolTip(iconComboBox.itemText(index));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
123 }
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
124
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
125 void iconActivated(QSystemTrayIcon.ActivationReason reason)
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
126 {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
127 switch (reason) {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
128 case QSystemTrayIcon.Trigger:
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
129 case QSystemTrayIcon.DoubleClick:
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
130 iconComboBox.setCurrentIndex((iconComboBox.currentIndex() + 1) % iconComboBox.count());
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
131 break;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
132 case QSystemTrayIcon.MiddleClick:
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
133 showMessage();
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
134 break;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
135 default:
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
136 }
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
137 }
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
138
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
139 void showMessage()
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
140 {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
141 QSystemTrayIcon.MessageIcon icon = cast(QSystemTrayIcon.MessageIcon)
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
142 typeComboBox.itemData(typeComboBox.currentIndex()).toInt();
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
143 trayIcon.showMessage(titleEdit.text(), bodyEdit.toPlainText(), icon, durationSpinBox.value() * 1000);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
144 }
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
145
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
146 void messageClicked()
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
147 {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
148 QMessageBox.information(null, tr("Systray"),
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
149 tr("Sorry, I already gave what help I could.\nMaybe you should try asking a human?"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
150 }
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
151
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
152 private:
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
153
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
154 void createIconGroupBox()
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
155 {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
156 iconGroupBox = new QGroupBox(tr("Tray Icon"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
157
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
158 iconLabel = new QLabel("Icon:");
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
159
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
160 iconComboBox = new QComboBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
161 iconComboBox.addItem(new QIcon(":/images/bad.svg"), tr("Bad"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
162 iconComboBox.addItem(new QIcon(":/images/heart.svg"), tr("Heart"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
163 iconComboBox.addItem(new QIcon(":/images/trash.svg"), tr("Trash"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
164
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
165 showIconCheckBox = new QCheckBox(tr("Show icon"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
166 showIconCheckBox.setChecked(true);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
167
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
168 QHBoxLayout iconLayout = new QHBoxLayout;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
169 iconLayout.addWidget(iconLabel);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
170 iconLayout.addWidget(iconComboBox);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
171 iconLayout.addStretch();
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
172 iconLayout.addWidget(showIconCheckBox);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
173 iconGroupBox.setLayout(iconLayout);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
174 }
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
175
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
176 void createMessageGroupBox()
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
177 {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
178 messageGroupBox = new QGroupBox(tr("Balloon Message"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
179
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
180 typeLabel = new QLabel(tr("Type:"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
181
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
182 typeComboBox = new QComboBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
183 typeComboBox.addItem(tr("None"), new QVariant(cast(ulong) QSystemTrayIcon.NoIcon));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
184 typeComboBox.addItem(style().standardIcon(
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
185 QStyle.SP_MessageBoxInformation), tr("Information"),
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
186 new QVariant(cast(ulong) QSystemTrayIcon.Information));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
187 typeComboBox.addItem(style().standardIcon(
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
188 QStyle.SP_MessageBoxWarning), tr("Warning"),
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
189 new QVariant(cast(ulong) QSystemTrayIcon.Warning));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
190 typeComboBox.addItem(style().standardIcon(
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
191 QStyle.SP_MessageBoxCritical), tr("Critical"),
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
192 new QVariant(cast(ulong) QSystemTrayIcon.Critical));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
193 typeComboBox.setCurrentIndex(1);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
194
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
195 durationLabel = new QLabel(tr("Duration:"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
196
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
197 durationSpinBox = new QSpinBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
198 durationSpinBox.setRange(5, 60);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
199 durationSpinBox.setSuffix(" s");
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
200 durationSpinBox.setValue(15);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
201
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
202 durationWarningLabel = new QLabel(tr("(some systems might ignore this hint)"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
203 durationWarningLabel.setIndent(10);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
204
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
205 titleLabel = new QLabel(tr("Title:"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
206
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
207 titleEdit = new QLineEdit(tr("Cannot connect to network"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
208
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
209 bodyLabel = new QLabel(tr("Body:"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
210
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
211 bodyEdit = new QTextEdit;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
212 bodyEdit.setPlainText(tr("Don't believe me. Honestly, I don't have a clue.\nClick this balloon for details."));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
213
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
214 showMessageButton = new QPushButton(tr("Show Message"));
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
215 showMessageButton.setDefault(true);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
216
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
217 QGridLayout messageLayout = new QGridLayout;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
218 messageLayout.addWidget(typeLabel, 0, 0);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
219 messageLayout.addWidget(typeComboBox, 0, 1, 1, 2);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
220 messageLayout.addWidget(durationLabel, 1, 0);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
221 messageLayout.addWidget(durationSpinBox, 1, 1);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
222 messageLayout.addWidget(durationWarningLabel, 1, 2, 1, 3);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
223 messageLayout.addWidget(titleLabel, 2, 0);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
224 messageLayout.addWidget(titleEdit, 2, 1, 1, 4);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
225 messageLayout.addWidget(bodyLabel, 3, 0);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
226 messageLayout.addWidget(bodyEdit, 3, 1, 2, 4);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
227 messageLayout.addWidget(showMessageButton, 5, 4);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
228 messageLayout.setColumnStretch(3, 1);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
229 messageLayout.setRowStretch(4, 1);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
230 messageGroupBox.setLayout(messageLayout);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
231 }
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
232
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
233 void createActions()
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
234 {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
235 minimizeAction = new QAction(tr("Mi&nimize"), this);
282
256ab6cb8e85 Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents: 120
diff changeset
236 connect!("triggered")(minimizeAction, &this.hide);
120
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
237
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
238 maximizeAction = new QAction(tr("Ma&ximize"), this);
282
256ab6cb8e85 Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents: 120
diff changeset
239 connect!("triggered")(maximizeAction, &this.showMaximized);
120
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
240
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
241 restoreAction = new QAction(tr("&Restore"), this);
282
256ab6cb8e85 Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents: 120
diff changeset
242 connect!("triggered")(restoreAction, &this.showNormal);
120
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
243
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
244 quitAction = new QAction(tr("&Quit"), this);
282
256ab6cb8e85 Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents: 120
diff changeset
245 connect!("triggered")(quitAction, &QApplication.quit);
120
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
246 }
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
247
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
248 void createTrayIcon()
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
249 {
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
250 trayIconMenu = new QMenu(this);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
251 trayIconMenu.addAction(minimizeAction);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
252 trayIconMenu.addAction(maximizeAction);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
253 trayIconMenu.addAction(restoreAction);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
254 trayIconMenu.addSeparator();
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
255 trayIconMenu.addAction(quitAction);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
256
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
257 trayIcon = new QSystemTrayIcon(this);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
258 trayIcon.setContextMenu(trayIconMenu);
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
259 }
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
260
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
261 QGroupBox iconGroupBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
262 QLabel iconLabel;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
263 QComboBox iconComboBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
264 QCheckBox showIconCheckBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
265
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
266 QGroupBox messageGroupBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
267 QLabel typeLabel;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
268 QLabel durationLabel;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
269 QLabel durationWarningLabel;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
270 QLabel titleLabel;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
271 QLabel bodyLabel;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
272 QComboBox typeComboBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
273 QSpinBox durationSpinBox;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
274 QLineEdit titleEdit;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
275 QTextEdit bodyEdit;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
276 QPushButton showMessageButton;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
277
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
278 QAction minimizeAction;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
279 QAction maximizeAction;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
280 QAction restoreAction;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
281 QAction quitAction;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
282
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
283 QSystemTrayIcon trayIcon;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
284 QMenu trayIconMenu;
2c9ef955a171 add desktop examples
mandel
parents:
diff changeset
285 }