Fri, 05 Dec 2008 23:14:02 +0100
Port to the Qt4 API and bump version pending release engineering.
1 //
2 // OSSP asgui - Accounting system graphical user interface
3 // Copyright (c) 2002-2008 The OSSP Project (http://www.ossp.org/)
4 // Copyright (c) 2002-2008 Ralf S. Engelschall <rse@engelschall.com>
5 // Copyright (c) 2002-2008 Michael Schloh von Bennewitz <michael@schloh.com>
6 // Copyright (c) 2002-2008 Cable & Wireless Telecommunications Services GmbH
7 //
8 // This file is part of OSSP asgui, an accounting system graphical user
9 // interface which can be found at http://asgui.europalab.com/.
10 //
11 // Permission to use, copy, modify, and distribute this software for
12 // any purpose with or without fee is hereby granted, provided that
13 // the above copyright notice and this permission notice appear in all
14 // copies.
15 //
16 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
17 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 // IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
20 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 // SUCH DAMAGE.
28 //
29 // as_assist.cpp: ISO C++ implementation
30 //
32 #define QT3_SUPPORT
34 #include <Qt3Support>
36 // Qt style headers
37 #include <qcdestyle.h>
38 #include <qcleanlooksstyle.h>
39 #include <qcommonstyle.h>
40 #include <qmotifstyle.h>
41 #include <qplastiquestyle.h>
42 #include <qwindowscestyle.h>
43 #include <qwindowsmobilestyle.h>
44 #include <qwindowsstyle.h>
45 #include <qwindowsvistastyle.h>
46 #include <qwindowsxpstyle.h>
48 // Qt general headers
49 #include <qtooltip.h>
50 #include <q3whatsthis.h>
51 #include <qstringlist.h>
52 #include <q3popupmenu.h>
53 #include <qcombobox.h>
54 #include <q3listbox.h>
55 #include <qstatusbar.h>
56 #include <qmenubar.h>
57 #include <qcursor.h>
58 #include <qaction.h>
59 #include <qrect.h>
60 #include <qdir.h>
62 //Added by qt3to4:
63 #include <QLabel>
64 #include <QPixmap>
65 #include <Q3TextStream>
66 #include <Q3HBoxLayout>
67 #include <Q3VBoxLayout>
68 #include <Q3Frame>
70 // User interface
71 #include "as_amount.h" // AmountBox class
72 #include "as_user.h" // User class
73 #include "as_const.h" // Application constants
74 #include "as_table.h" // Class TiTable
75 #include "as_pref.h" // Class Preferences
76 #include "as_panel.h" // Class Prefpanel
77 #include "as_datedit.h" // Class Daydateedit
79 // Icon pixel maps
80 #include "as_gfx/filenew.xpm" // static const char *s_kpcFilenew_xpm[]
81 #include "as_gfx/fileopen.xpm" // static const char *s_kpcFileopen_xpm[]
82 #include "as_gfx/filesave.xpm" // static const char *s_kpcFilesave_xpm[]
83 #include "as_gfx/filesaved.xpm" // static const char *s_kpcDfilesave_xpm[]
84 #include "as_gfx/cut.xpm" // static const char *s_kpcCut_xpm[]
85 #include "as_gfx/cutd.xpm" // static const char *s_kpcDcut_xpm[]
86 #include "as_gfx/copy.xpm" // static const char *s_kpcCopy_xpm[]
87 #include "as_gfx/copyd.xpm" // static const char *s_kpcDcopy_xpm[]
88 #include "as_gfx/paste.xpm" // static const char *s_kpcPaste_xpm[]
89 #include "as_gfx/pasted.xpm" // static const char *s_kpcDcaste_xpm[]
90 #include "as_gfx/rowadd.xpm" // static const char *s_kpcRowadd_xpm[]
91 #include "as_gfx/rowdel.xpm" // static const char *s_kpcRowdel_xpm[]
92 #include "as_gfx/rowaddd.xpm" // static const char *s_kpcDrowadd_xpm[]
93 #include "as_gfx/rowdeld.xpm" // static const char *s_kpcDrowdel_xpm[]
94 #include "as_gfx/osspicon.xpm" // static const char *s_kpcOsspicon_xpm[]
95 #include "as_gfx/whatsthis.xpm" // static const char *s_kpcWhatsthis_xpm[]
96 #include "as_gfx/statok.xpm" // static const char *s_kpcStatokay_xpm[]
97 #include "as_gfx/staterr.xpm" // static const char *s_kpcStaterror_xpm[]
98 #include "as_gfx/statwrn.xpm" // static const char *s_kpcStatwarn_xpm[]
99 #include "as_gfx/statvoid.xpm" // static const char *s_kpcStatvoid_xpm[]
100 #include "as_gfx/refresh.xpm" // static const char *s_kpcRefresh_xpm[]
101 #include "as_gfx/refreshd.xpm" // static const char *s_kpcDrefresh_xpm[]
102 #include "as_gfx/sync.xpm" // static const char *s_kpcSync_xpm[]
103 #include "as_gfx/syncd.xpm" // static const char *s_kpcDsync_xpm[]
104 #include "as_gfx/report.xpm" // static const char *s_kpcReport_xpm[]
105 #include "as_gfx/reportd.xpm" // static const char *s_kpcDreport_xpm[]
106 #include "as_gfx/prefs.xpm" // static const char *s_kpcPrefs_xpm[]
109 //
110 // Construct the preferences
111 //
112 void Titraqform::setupPrefs(void)
113 {
114 // Can't bootstrap until we know who is using our tool, so find out
115 User Localuser = User();
116 QString Username = QString::fromStdString(Localuser.getName());
117 QString Homedir = QString::fromStdString(Localuser.getHomedir());
119 // Bootstrap a user preferences object from operating system info
120 m_pPrefs = new Preferences(Homedir + QChar('/') +
121 QString::fromLocal8Bit(TITRAQ_PREFNAME),
122 QString::fromLocal8Bit(TITRAQ_APPTITLE),
123 QString::fromLocal8Bit(TITRAQ_PREFVER));
124 if (!m_pPrefs->fileState()) { // No file was found, so assume a null state
125 if (!Homedir.isEmpty())
126 m_pPrefs->setString(TITRAQ_PREFHOME, Homedir);
127 else
128 m_pPrefs->setString(TITRAQ_PREFHOME, TITRAQ_DEFHOME);
129 if (!Username.isEmpty())
130 m_pPrefs->setString(TITRAQ_PREFUSER, Username);
131 else
132 m_pPrefs->setString(TITRAQ_PREFUSER, TITRAQ_DEFUSER);
134 m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLECDE);
135 m_pPrefs->setString(TITRAQ_PREFACCOUNTS, TITRAQ_DEFACCOUNTS);
136 m_pPrefs->setString(TITRAQ_PREFASDIR, TITRAQ_DEFASDIR);
137 m_pPrefs->setString(TITRAQ_PREFVIEW, TITRAQ_DEFVIEW);
138 m_pPrefs->setNumber(TITRAQ_PREFSORTCOL, TITRAQ_DEFSORTCOL);
139 m_pPrefs->setBool(TITRAQ_PREFSORTDIR, TITRAQ_DEFSORTDIR);
140 m_pPrefs->setString(TITRAQ_PREFREMOTELOG, TITRAQ_DEFREMOTELOG);
141 m_pPrefs->setString(TITRAQ_PREFLOCALLOG, TITRAQ_DEFLOCALLOG);
142 m_pPrefs->setString(TITRAQ_PREFCORBHOST, TITRAQ_DEFCORBHOST);
143 m_pPrefs->setString(TITRAQ_PREFSOAPHOST, TITRAQ_DEFSOAPHOST);
144 m_pPrefs->setBool(TITRAQ_PREFCORBON, TITRAQ_DEFCORBON);
145 m_pPrefs->setBool(TITRAQ_PREFSOAPON, TITRAQ_DEFSOAPON);
146 m_pPrefs->setBool(TITRAQ_PREFBAKON, TITRAQ_DEFBAKON);
147 m_pPrefs->setBool(TITRAQ_PREFEXTENDON, TITRAQ_DEFEXTENDON);
148 m_pPrefs->setBool(TITRAQ_PREFDETAILON, TITRAQ_DEFDETAILON);
149 m_pPrefs->setBool(TITRAQ_PREFSIGNATON, TITRAQ_DEFSIGNATON);
150 m_pPrefs->setNumber(TITRAQ_PREFREPORTYPE, TITRAQ_DEFREPORTYPE);
151 m_pPrefs->setNumber(TITRAQ_PREFREPORTWEEKS, TITRAQ_DEFREPORTWEEKS);
152 m_pPrefs->setNumber(TITRAQ_PREFREPORTMONTHS, TITRAQ_DEFREPORTMONTHS);
153 m_pPrefs->setNumber(TITRAQ_PREFLIGHTRED, TITRAQ_DEFLIGHTRED);
154 m_pPrefs->setNumber(TITRAQ_PREFLIGHTGREEN, TITRAQ_DEFLIGHTGREEN);
155 m_pPrefs->setNumber(TITRAQ_PREFLIGHTBLUE, TITRAQ_DEFLIGHTBLUE);
156 m_pPrefs->setNumber(TITRAQ_PREFDARKRED, TITRAQ_DEFDARKRED);
157 m_pPrefs->setNumber(TITRAQ_PREFDARKGREEN, TITRAQ_DEFDARKGREEN);
158 m_pPrefs->setNumber(TITRAQ_PREFDARKBLUE, TITRAQ_DEFDARKBLUE);
159 m_pPrefs->flush(); // Write the new conf file
160 Q3TextStream cerr(stderr, QIODevice::WriteOnly);
161 cerr << trUtf8("Created new preferences file ") << Homedir << QChar('/')
162 << QString::fromLocal8Bit(TITRAQ_PREFNAME) << endl;
163 }
165 // Use the preferred configuration values to initialize titraq
166 switch (m_pPrefs->getNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLECDE)) {
167 case TITRAQ_STYLECDE:
168 qApp->setStyle(new QCDEStyle);
169 break;
170 //case TITRAQ_STYLESGI: // SGI Style is unsupported
171 // qApp->setStyle(new QSGIStyle);
172 // break;
173 case TITRAQ_STYLEMOTIF:
174 qApp->setStyle(new QMotifStyle);
175 break;
176 //case TITRAQ_STYLEMPLUS: // MotifPlus Style is unsupported
177 // qApp->setStyle(new QMotifPlusStyle);
178 // break;
179 //case TITRAQ_STYLEPLAT: // Platinum Style is unsupported
180 // qApp->setStyle(new QPlatinumStyle);
181 // break;
182 case TITRAQ_STYLEMSOFT:
183 qApp->setStyle(new QWindowsStyle);
184 break;
185 default:
186 qApp->setStyle(new QCDEStyle);
187 break;
188 }
189 }
191 //
192 // Construct various actions
193 //
194 void Titraqform::setupActions(void)
195 {
196 QIcon Saveiset, Cutiset, Copyiset, Pasteiset;
197 QIcon Rowaddiset, Rowdeliset, Refreshiset;
198 QIcon Synciset, Reportiset;
200 // Construct iconsets to use later for multistate action images
201 Saveiset.setPixmap(QPixmap(s_kpcFilesave_xpm), QIcon::Automatic, QIcon::Normal);
202 Saveiset.setPixmap(QPixmap(s_kpcDfilesave_xpm), QIcon::Automatic, QIcon::Disabled);
203 Cutiset.setPixmap(QPixmap(s_kpcCut_xpm), QIcon::Automatic, QIcon::Normal);
204 Cutiset.setPixmap(QPixmap(s_kpcDcut_xpm), QIcon::Automatic, QIcon::Disabled);
205 Copyiset.setPixmap(QPixmap(s_kpcCopy_xpm), QIcon::Automatic, QIcon::Normal);
206 Copyiset.setPixmap(QPixmap(s_kpcDcopy_xpm), QIcon::Automatic, QIcon::Disabled);
207 Pasteiset.setPixmap(QPixmap(s_kpcPaste_xpm), QIcon::Automatic, QIcon::Normal);
208 Pasteiset.setPixmap(QPixmap(s_kpcDpaste_xpm), QIcon::Automatic, QIcon::Disabled);
209 Rowaddiset.setPixmap(QPixmap(s_kpcRowadd_xpm), QIcon::Automatic, QIcon::Normal);
210 Rowaddiset.setPixmap(QPixmap(s_kpcDrowadd_xpm), QIcon::Automatic, QIcon::Disabled);
211 Rowdeliset.setPixmap(QPixmap(s_kpcRowdel_xpm), QIcon::Automatic, QIcon::Normal);
212 Rowdeliset.setPixmap(QPixmap(s_kpcDrowdel_xpm), QIcon::Automatic, QIcon::Disabled);
213 Refreshiset.setPixmap(QPixmap(s_kpcRefresh_xpm), QIcon::Automatic, QIcon::Normal);
214 Refreshiset.setPixmap(QPixmap(s_kpcDrefresh_xpm), QIcon::Automatic, QIcon::Disabled);
215 Synciset.setPixmap(QPixmap(s_kpcSync_xpm), QIcon::Automatic, QIcon::Normal);
216 Synciset.setPixmap(QPixmap(s_kpcDsync_xpm), QIcon::Automatic, QIcon::Disabled);
217 Reportiset.setPixmap(QPixmap(s_kpcReport_xpm), QIcon::Automatic, QIcon::Normal);
218 Reportiset.setPixmap(QPixmap(s_kpcDreport_xpm), QIcon::Automatic, QIcon::Disabled);
220 // First associate the graphics with MIME types
221 Q3MimeSourceFactory::defaultFactory()->setPixmap("osspicon", QPixmap(s_kpcOsspicon_xpm));
222 Q3MimeSourceFactory::defaultFactory()->setPixmap("filenew", QPixmap(s_kpcFilenew_xpm));
223 Q3MimeSourceFactory::defaultFactory()->setPixmap("fileopen", QPixmap(s_kpcFileopen_xpm));
224 Q3MimeSourceFactory::defaultFactory()->setPixmap("filesave", QPixmap(s_kpcFilesave_xpm));
225 Q3MimeSourceFactory::defaultFactory()->setPixmap("cut", QPixmap(s_kpcCut_xpm));
226 Q3MimeSourceFactory::defaultFactory()->setPixmap("copy", QPixmap(s_kpcCopy_xpm));
227 Q3MimeSourceFactory::defaultFactory()->setPixmap("paste", QPixmap(s_kpcPaste_xpm));
228 Q3MimeSourceFactory::defaultFactory()->setPixmap("rowadd", QPixmap(s_kpcRowadd_xpm));
229 Q3MimeSourceFactory::defaultFactory()->setPixmap("rowdel", QPixmap(s_kpcRowdel_xpm));
230 Q3MimeSourceFactory::defaultFactory()->setPixmap("refresh", QPixmap(s_kpcRefresh_xpm));
231 Q3MimeSourceFactory::defaultFactory()->setPixmap("syncrpc", QPixmap(s_kpcSync_xpm));
232 Q3MimeSourceFactory::defaultFactory()->setPixmap("locreport", QPixmap(s_kpcReport_xpm));
233 Q3MimeSourceFactory::defaultFactory()->setPixmap("prefs", QPixmap(s_kpcPrefs_xpm));
235 // File new action
236 m_pFilenewact = new Q3Action(trUtf8("New File"), QPixmap(s_kpcFilenew_xpm), trUtf8("&New"), Qt::CTRL+Qt::Key_N, this, "New");
237 if (m_pFilenewact == NULL) // Sanity check
238 throw Genexcept("Main window file new action creation failed.");
239 connect(m_pFilenewact, SIGNAL(activated()), SLOT(newDoc()));
240 const char *kszFilenewtext = "<p><img source=\"filenew\"> "
241 "Click this button to make a "
242 "<em>blank file</em>. You can also "
243 "select the <b>New</b> command from "
244 "the <b>File</b> menu.</p>";
245 m_pFilenewact->setWhatsThis(kszFilenewtext);
247 // File open action
248 m_pFileopenact = new Q3Action(trUtf8("Open File"), QPixmap(s_kpcFileopen_xpm), trUtf8("&Open..."), Qt::CTRL+Qt::Key_O, this, "Open");
249 if (m_pFileopenact == NULL) // Sanity check
250 throw Genexcept("Main window file open action creation failed.");
251 connect(m_pFileopenact, SIGNAL(activated()), SLOT(openDoc()));
252 const char *kszFileopentext = "<p><img source=\"fileopen\"> "
253 "Click this button to open a "
254 "<em>new file</em>. You can also select "
255 "the <b>Open</b> command from the "
256 "<b>File</b> menu.</p>";
257 m_pFileopenact->setWhatsThis(kszFileopentext);
259 // File save current action
260 m_pFilesaveact = new Q3Action(trUtf8("Save File"), Saveiset, trUtf8("&Save"), Qt::CTRL+Qt::Key_S, this, "Save");
261 if (m_pFilesaveact == NULL) // Sanity check
262 throw Genexcept("Main window file save action creation failed.");
263 connect(m_pFilesaveact, SIGNAL(activated()), SLOT(saveFile()));
264 const char *kszFilesavetext = "<p><img source=\"filesave\"> "
265 "Click this button to <em>save</em> "
266 "the file you are editing. You will be "
267 "prompted for a file name. You can also "
268 "select the<b> Save</b> command from "
269 "the <b>File</b> menu.</p>";
270 m_pFilesaveact->setWhatsThis(kszFilesavetext);
272 // File save selected action
273 m_pFilesaveasact = new Q3Action(trUtf8("Save File As"), trUtf8("Save &As..."), 0, this, "SaveAs");
274 if (m_pFilesaveasact == NULL) // Sanity check
275 throw Genexcept("Main window file save as action creation failed.");
276 connect(m_pFilesaveasact, SIGNAL(activated()), SLOT(saveAs()));
277 m_pFilesaveasact->setWhatsThis(kszFilesavetext);
279 // File close current action
280 m_pFilecloseact = new Q3Action(trUtf8("Close"), trUtf8("&Close"), Qt::CTRL+Qt::Key_W, this, "Close");
281 if (m_pFilecloseact == NULL) // Sanity check
282 throw Genexcept("Main window file close action creation failed.");
283 connect(m_pFilecloseact, SIGNAL(activated()), SLOT(close()));
285 // File quit action
286 m_pFilequitact = new Q3Action(trUtf8("Exit"), trUtf8("E&xit"), Qt::CTRL+Qt::Key_Q, this, "Exit");
287 if (m_pFilequitact == NULL) // Sanity check
288 throw Genexcept("Main window file quit action creation failed.");
289 connect(m_pFilequitact, SIGNAL(activated()), SLOT(quitApp()));
291 // Cut action
292 m_pCutact = new Q3Action(trUtf8("Cut"), Cutiset, trUtf8("&Cut"), Qt::CTRL+Qt::Key_X, this, "Cut");
293 if (m_pCutact == NULL) // Sanity check
294 throw Genexcept("Main window cut edit action creation failed.");
295 connect(m_pCutact, SIGNAL(activated()), SLOT(cutEntry()));
296 const char *kszCuttext = "<p><img source=\"cut\"> "
297 "Click this button to cut an <em>entry</em>. "
298 "You can also select the <b>Cut</b> command "
299 "from the <b>Edit</b> menu.</p>";
300 m_pCutact->setWhatsThis(kszCuttext);
302 // Copy action
303 m_pCopyact = new Q3Action(trUtf8("Copy"), Copyiset, trUtf8("&Copy"), Qt::CTRL+Qt::Key_C, this, "Copy");
304 if (m_pCopyact == NULL) // Sanity check
305 throw Genexcept("Main window copy edit action creation failed.");
306 connect(m_pCopyact, SIGNAL(activated()), SLOT(copyEntry()));
307 const char *kszCopytext = "<p><img source=\"copy\"> "
308 "Click this button to copy an <em>entry</em>. "
309 "You can also select the <b>Copy</b> command "
310 "from the <b>Edit</b> menu.</p>";
311 m_pCopyact->setWhatsThis(kszCopytext);
313 // Paste action
314 m_pPasteact = new Q3Action(trUtf8("Paste"), Pasteiset, trUtf8("&Paste"), Qt::CTRL+Qt::Key_V, this, "Paste");
315 if (m_pPasteact == NULL) // Sanity check
316 throw Genexcept("Main window paste edit action creation failed.");
317 connect(m_pPasteact, SIGNAL(activated()), SLOT(pasteEntry()));
318 const char *kszPastetext = "<p><img source=\"paste\"> "
319 "Click this button to paste an <em>entry</em>. "
320 "You can also select the <b>Paste</b> command "
321 "from the <b>Edit</b> menu.</p>";
322 m_pPasteact->setWhatsThis(kszPastetext);
324 // Add data row action
325 m_pAddrowact = new Q3Action(trUtf8("Add Entry"), Rowaddiset, trUtf8("&Add entry"), Qt::Key_Insert, this, "Addentry");
326 if (m_pAddrowact == NULL) // Sanity check
327 throw Genexcept("Main window add entry action creation failed.");
328 connect(m_pAddrowact, SIGNAL(activated()), SLOT(addEntry()));
329 const char *kszAddrowtext = "<p><img source=\"rowadd\"> "
330 "Click this button to add a <em>new entry</em>. "
331 "You can also select the <b>Add</b> command "
332 "from the <b>Edit</b> menu.</p>";
333 m_pAddrowact->setWhatsThis(kszAddrowtext);
335 // Delete data row action
336 m_pDelrowact = new Q3Action(trUtf8("Delete Entry"), Rowdeliset, trUtf8("&Delete entry"), Qt::Key_Delete, this, "Delentry");
337 if (m_pDelrowact == NULL) // Sanity check
338 throw Genexcept("Main window delete entry action creation failed.");
339 connect(m_pDelrowact, SIGNAL(activated()), SLOT(delEntry()));
340 const char *kszDelrowtext = "<p><img source=\"rowdel\"> "
341 "Click this button to delete a <em>entry</em>. "
342 "You can also select the <b>Delete</b> command "
343 "from the <b>Edit</b> menu.</p>";
344 m_pDelrowact->setWhatsThis(kszDelrowtext);
346 // Refresh data display action
347 m_pRefreshact = new Q3Action(trUtf8("Refresh Display"), Refreshiset, trUtf8("&Refresh display"), Qt::CTRL+Qt::Key_R, this, "Refresh");
348 if (m_pRefreshact == NULL) // Sanity check
349 throw Genexcept("Main window refresh action creation failed.");
350 connect(m_pRefreshact, SIGNAL(activated()), SLOT(refreshDisplay()));
351 const char *kszRefreshtext = "<p><img source=\"refresh\"> "
352 "Click this button to <em>refresh the display</em>. "
353 "You can also select the <b>Refresh</b> command "
354 "from the <b>View</b> menu.</p>";
355 m_pRefreshact->setWhatsThis(kszRefreshtext);
357 // Syncronize data with remote server over IIOP or SOAP action
358 m_pSyncact = new Q3Action(trUtf8("Synchronize with server"), Synciset, trUtf8("&Synchronize"), Qt::CTRL+Qt::Key_E, this, "Synchronize");
359 if (m_pSyncact == NULL) // Sanity check
360 throw Genexcept("Main window synchronize RPC action creation failed.");
361 connect(m_pSyncact, SIGNAL(activated()), SLOT(syncIiop()));
362 connect(m_pSyncact, SIGNAL(activated()), SLOT(syncSoap()));
363 const char *kszSynctext = "<p><img source=\"syncrpc\"> "
364 "Click this button to <em>synchronize the data</em>. "
365 "Your changed entries will be sent to the server. "
366 "You can also select the <b>Synchronize</b> command "
367 "from the <b>Report</b> menu.</p>";
368 m_pSyncact->setWhatsThis(kszSynctext);
370 // Local report generation action
371 m_pReportact = new Q3Action(trUtf8("Generate a local report"), Reportiset, trUtf8("&Report"), Qt::CTRL+Qt::Key_T, this, "LocalReport");
372 if (m_pReportact == NULL) // Sanity check
373 throw Genexcept("Main window local report action creation failed.");
374 connect(m_pReportact, SIGNAL(activated()), SLOT(genReport()));
375 const char *kszReporttext = "<p><img source=\"locreport\"> "
376 "Click this button to <em>report your data</em>. "
377 "A local report will be generated for you to view. "
378 "You can also select the <b>Local Report</b> command "
379 "from the <b>Report</b> menu.</p>";
380 m_pReportact->setWhatsThis(kszReporttext);
382 // Offer a formatted preferences panel for intuitive prefs object editing
383 m_pPrefsact = new Q3Action(trUtf8("Edit the preferences"), QPixmap(s_kpcPrefs_xpm), trUtf8("P&references..."), Qt::CTRL+Qt::Key_F, this, "Prefspanel");
384 if (m_pPrefsact == NULL) // Sanity check
385 throw Genexcept("Main window preferences panel action creation failed.");
386 connect(m_pPrefsact, SIGNAL(activated()), SLOT(configPrefs()));
387 const char *kszPrefstext = "<p><img source=\"prefs\"> "
388 "Click this button to <em>edit the preferences</em>. "
389 "You can then apply, accept, or cancel your changes. "
390 "You can also select the <b>Preferences</b> command "
391 "from the <b>Edit</b> menu.</p>";
392 m_pPrefsact->setWhatsThis(kszPrefstext);
393 }
395 //
396 // Construct the menu bar
397 //
398 void Titraqform::setupMenubar(void)
399 {
400 int nMenuid = 0; // Used to store id during menu item creation
402 m_pMenubar = menuBar(); // Grab menu bar owned by QMainWindow
403 if (m_pMenubar == NULL) // Sanity check
404 throw Genexcept("Main window menu bar nonexistant.");
406 // // Make an easter egg ;-)
407 // QToolTip::add(m_pMenubar, QRect(0, 0, 2, 2), trUtf8("Easter Egg"));
409 // Construct and populate the file menu with actions
410 Q3PopupMenu *pFilepopup = new Q3PopupMenu(this);
411 if (pFilepopup == NULL) // Sanity check
412 throw Genexcept("Main window file popup creation failed.");
413 m_pMenubar->insertItem(trUtf8("&File"), pFilepopup);
414 m_pFilenewact->addTo(pFilepopup);
415 m_pFileopenact->addTo(pFilepopup);
416 pFilepopup->insertSeparator();
417 m_pFilecloseact->addTo(pFilepopup);
418 pFilepopup->insertSeparator();
419 m_pFilesaveact->addTo(pFilepopup);
420 m_pFilesaveasact->addTo(pFilepopup);
421 pFilepopup->insertSeparator();
422 m_pFilequitact->addTo(pFilepopup);
424 // Construct and populate the edit menu with subitems
425 Q3PopupMenu *pEditpopup = new Q3PopupMenu(this);
426 if (pEditpopup == NULL) // Sanity check
427 throw Genexcept("Main window edit popup creation failed.");
428 m_pMenubar->insertItem(trUtf8("&Edit"), pEditpopup);
429 m_pCutact->addTo(pEditpopup);
430 m_pCopyact->addTo(pEditpopup);
431 m_pPasteact->addTo(pEditpopup);
432 pEditpopup->insertSeparator();
433 m_pAddrowact->addTo(pEditpopup);
434 m_pDelrowact->addTo(pEditpopup);
435 pEditpopup->insertSeparator();
436 m_pPrefsact->addTo(pEditpopup);
438 // Construct the view menu and submenus
439 m_pViewpopup = new Q3PopupMenu(this);
440 m_pTbarspopup = new Q3PopupMenu(this);
441 m_pColspopup = new Q3PopupMenu(this);
443 // Give the new menus krass attributes
444 m_pTbarspopup->insertTearOffHandle();
445 m_pTbarspopup->setCheckable(true);
446 m_pColspopup->insertTearOffHandle();
447 m_pColspopup->setCheckable(true);
449 // Major sanity check wrapped in one call
450 if (!(m_pViewpopup && m_pTbarspopup && m_pColspopup))
451 throw Genexcept("Main window view popups creation failed.");
453 // Populate the view menu with subitems
454 m_pMenubar->insertItem(trUtf8("&View"), m_pViewpopup);
455 m_pViewpopup->insertItem(trUtf8("&Normal"), this, SLOT(normalView()));
456 nMenuid = m_pViewpopup->insertItem(trUtf8("&Editing"), this, SLOT(editingView()));
457 m_pViewpopup->setItemEnabled(nMenuid, false);
458 nMenuid = m_pViewpopup->insertItem(trUtf8("&Timing"), this, SLOT(timingView()));
459 m_pViewpopup->setItemEnabled(nMenuid, false);
460 m_pViewpopup->insertSeparator();
461 m_pRefreshact->addTo(m_pViewpopup); // Refresh action
462 m_pViewpopup->insertSeparator();
463 m_pViewpopup->insertItem(trUtf8("&Toolbars"), m_pTbarspopup);
464 nMenuid = m_pTbarspopup->insertItem(trUtf8("&File"), this, SLOT(showFilebar()));
465 m_pTbarspopup->setItemChecked(nMenuid, true);
466 nMenuid = m_pTbarspopup->insertItem(trUtf8("&Edit"), this, SLOT(showEditbar()));
467 m_pTbarspopup->setItemChecked(nMenuid, true);
468 nMenuid = m_pTbarspopup->insertItem(trUtf8("&View"), this, SLOT(showViewbar()));
469 m_pTbarspopup->setItemChecked(nMenuid, true);
470 nMenuid = m_pTbarspopup->insertItem(trUtf8("&Prefs"), this, SLOT(showPrefsbar()));
471 m_pTbarspopup->setItemChecked(nMenuid, true);
472 nMenuid = m_pTbarspopup->insertItem(trUtf8("&Whats"), this, SLOT(showWhatsbar()));
473 m_pTbarspopup->setItemChecked(nMenuid, true);
474 m_pViewpopup->insertItem(trUtf8("&Columns"), m_pColspopup);
475 nMenuid = m_pColspopup->insertItem(trUtf8("&Status"), this, SLOT(showStatcol()));
476 m_pColspopup->setItemChecked(nMenuid, true);
477 nMenuid = m_pColspopup->insertItem(trUtf8("&Line"), this, SLOT(showLinecol()));
478 m_pColspopup->setItemChecked(nMenuid, true);
479 nMenuid = m_pColspopup->insertItem(trUtf8("&User"), this, SLOT(showUsercol()));
480 m_pColspopup->setItemChecked(nMenuid, true);
481 nMenuid = m_pColspopup->insertItem(trUtf8("&GUID"), this, SLOT(showGuidcol()));
482 m_pColspopup->setItemChecked(nMenuid, true);
483 nMenuid = m_pColspopup->insertItem(trUtf8("&CRC"), this, SLOT(showCrccol()));
484 m_pColspopup->setItemChecked(nMenuid, true);
485 nMenuid = m_pColspopup->insertItem(trUtf8("&Rev"), this, SLOT(showRevcol()));
486 m_pColspopup->setItemChecked(nMenuid, true);
487 nMenuid = m_pColspopup->insertItem(trUtf8("&Date"), this, SLOT(showDatecol()));
488 m_pColspopup->setItemChecked(nMenuid, true);
489 nMenuid = m_pColspopup->insertItem(trUtf8("&Start"), this, SLOT(showStartcol()));
490 m_pColspopup->setItemChecked(nMenuid, true);
491 nMenuid = m_pColspopup->insertItem(trUtf8("&Finish"), this, SLOT(showFinishcol()));
492 m_pColspopup->setItemChecked(nMenuid, true);
493 nMenuid = m_pColspopup->insertItem(trUtf8("&Amount"), this, SLOT(showAmountcol()));
494 m_pColspopup->setItemChecked(nMenuid, true);
495 nMenuid = m_pColspopup->insertItem(trUtf8("&Task"), this, SLOT(showTaskcol()));
496 m_pColspopup->setItemChecked(nMenuid, true);
497 nMenuid = m_pColspopup->insertItem(trUtf8("&Remark"), this, SLOT(showRemarkcol()));
498 m_pColspopup->setItemChecked(nMenuid, true);
500 // Construct and populate the report menu with subitems
501 Q3PopupMenu *pReportpopup = new Q3PopupMenu(this);
502 if (pReportpopup == NULL) // Sanity check
503 throw Genexcept("Main window report popup creation failed.");
504 m_pMenubar->insertItem(trUtf8("&Report"), pReportpopup);
505 #if defined HAVE_MICO || defined HAVE_ESOAP
506 m_pSyncact->addTo(pReportpopup);
507 m_pSyncact->setEnabled(m_pPrefs->getBool(TITRAQ_PREFCORBON, TITRAQ_DEFCORBON)
508 | m_pPrefs->getBool(TITRAQ_PREFSOAPON, TITRAQ_DEFSOAPON));
509 #endif // defined HAVE_MICO || defined HAVE_ESOAP
510 m_pReportact->addTo(pReportpopup);
512 // Pad spacing to force help menu to appear far right
513 m_pMenubar->insertSeparator();
515 // Construct and populate the help menu with subitems
516 Q3PopupMenu *pHelppopup = new Q3PopupMenu(this);
517 if (pHelppopup == NULL) // Sanity check
518 throw Genexcept("Main window help popup creation failed.");
519 m_pMenubar->insertItem(trUtf8("&Help"), pHelppopup);
520 pHelppopup->insertItem(trUtf8("&Contents"), this, SLOT(helpContents()), Qt::Key_F1);
521 pHelppopup->insertSeparator();
522 pHelppopup->insertItem(trUtf8("About &as-gui"), this, SLOT(aboutTitraq()));
523 pHelppopup->insertItem(trUtf8("About &OSSP"), this, SLOT(aboutOSSP()));
524 pHelppopup->insertItem(trUtf8("About &Qt"), this, SLOT(aboutQt()));
525 pHelppopup->insertSeparator();
526 pHelppopup->insertItem(QPixmap(s_kpcWhatsthis_xpm), trUtf8("What's &This"), this, SLOT(whatsThis()), Qt::SHIFT+Qt::Key_F1);
527 }
529 //
530 // Construct the tool bars
531 //
532 void Titraqform::setupToolbars(void)
533 {
534 // Construct and populate the file tool bar
535 m_pFiletools = new Q3ToolBar("Toolfile", this, Qt::DockTop);
536 if (m_pFiletools == NULL) // Sanity check
537 throw Genexcept("File tool bar creation failed.");
538 m_pFiletools->setLabel(trUtf8("File Ops"));
539 m_pFiletools->setOpaqueMoving(false);
540 m_pFiletools->setCloseMode(Q3DockWindow::Never);
541 m_pFilenewact->addTo(m_pFiletools);
542 m_pFileopenact->addTo(m_pFiletools);
543 m_pFilesaveact->addTo(m_pFiletools);
545 // Construct and populate the edit tool bar
546 m_pEdittools = new Q3ToolBar("Tooledit", this, Qt::DockTop);
547 if (m_pEdittools == NULL) // Sanity check
548 throw Genexcept("Edit tool bar creation failed.");
549 m_pEdittools->setLabel(trUtf8("Edit Ops"));
550 m_pEdittools->setOpaqueMoving(false);
551 m_pEdittools->setCloseMode(Q3DockWindow::Never);
552 m_pCutact->addTo(m_pEdittools);
553 m_pCopyact->addTo(m_pEdittools);
554 m_pPasteact->addTo(m_pEdittools);
555 m_pEdittools->addSeparator();
556 m_pAddrowact->addTo(m_pEdittools);
557 m_pDelrowact->addTo(m_pEdittools);
559 // Construct and populate the view tool bar
560 m_pViewtools = new Q3ToolBar("Toolview", this, Qt::DockTop);
561 if (m_pViewtools == NULL) // Sanity check
562 throw Genexcept("View tool bar creation failed.");
563 m_pViewtools->setLabel(trUtf8("View Ops"));
564 m_pViewtools->setOpaqueMoving(false);
565 m_pViewtools->setCloseMode(Q3DockWindow::Never);
566 m_pRefreshact->addTo(m_pViewtools);
567 m_pReportact->addTo(m_pViewtools);
568 m_pSyncact->addTo(m_pViewtools);
570 // Construct and populate the lonely preferences tool bar
571 m_pPrefstools = new Q3ToolBar("Preferences", this, Qt::DockTop);
572 if (m_pPrefstools == NULL) // Sanity check
573 throw Genexcept("Prefs tool bar creation failed.");
574 m_pPrefstools->setLabel(trUtf8("Preferences editor"));
575 m_pPrefstools->setOpaqueMoving(false);
576 m_pPrefstools->setCloseMode(Q3DockWindow::Never);
577 m_pPrefsact->addTo(m_pPrefstools);
579 // Construct and populate the lonely whatsthis tool bar
580 m_pWhatstools = new Q3ToolBar("Toolwhats", this, Qt::DockTop);
581 if (m_pWhatstools == NULL) // Sanity check
582 throw Genexcept("Whats this tool bar creation failed.");
583 m_pWhatstools->setLabel(trUtf8("Whats this"));
584 m_pWhatstools->setOpaqueMoving(false);
585 m_pWhatstools->setCloseMode(Q3DockWindow::Never);
586 Q3WhatsThis::whatsThisButton(m_pWhatstools); // Preconfigured whats this button
587 }
589 //
590 // Construct the central frame
591 //
592 void Titraqform::setupCentralwidget(void)
593 {
594 // Create a central frame and associated layout for QMainWindow
595 m_pCenframe = new Q3Frame(this, "Centralframe");
596 if (m_pCenframe == NULL) // Sanity check
597 throw Genexcept("Main window central frame creation failed.");
598 m_pCenframe->setFrameShape(Q3Frame::StyledPanel);
599 m_pCenframe->setFrameShadow(Q3Frame::Sunken);
600 this->setCentralWidget(m_pCenframe);
602 // Layout controls for table, editing widgets
603 m_pMainlayout = new Q3VBoxLayout(m_pCenframe, TITRAQ_MARGIN, TITRAQ_SPACING, "Mainlayout"); // For layouts
604 m_pPackagelayout = new Q3VBoxLayout(0, 0, TITRAQ_SPACING, "Packagelayout"); // For table
605 m_pEditlayout = new Q3HBoxLayout(0, 0, TITRAQ_SPACING, "Editlayout"); // For edits
607 // Major sanity check wrapped in one call
608 if (!(m_pMainlayout && m_pPackagelayout && m_pEditlayout))
609 throw Genexcept("Main window layout creation failed.");
611 // Specify ordering of the layouts
612 m_pMainlayout->addLayout(m_pPackagelayout);
613 m_pMainlayout->addLayout(m_pEditlayout);
614 }
616 //
617 // Construct the status bar
618 //
619 void Titraqform::setupStatusbar(void)
620 {
621 m_pStatbar = statusBar(); // Grab status bar owned by QMainWindow
622 if (m_pStatbar == NULL) // Sanity check
623 throw Genexcept("Main window status bar nonexistant.");
624 }
626 //
627 // Construct the table
628 //
629 void Titraqform::setupTable(void)
630 {
631 // Create, configure, and setup the table itself
632 m_pMaintable = new TiTable(m_pPrefs, m_pCenframe, "Maintable");
633 if (m_pMaintable == NULL) // Sanity check
634 throw Genexcept("Main window table creation failed.");
635 m_pMaintable->setNumCols(TITRAQ_IDXTAIL);
636 m_pMaintable->setDirty(false); // Reset data to clean state
637 m_pMaintable->setReadOnly(true); // Table is read only
638 m_pMaintable->setColumnMovingEnabled(false); // Ctrl-drag disabled
639 m_pMaintable->setSelectionMode(Q3Table::MultiRow); // Multi row selection
640 m_pMaintable->setFocusStyle(Q3Table::FollowStyle); // How cells are drawn
641 m_pMaintable->setLeftMargin(0); // Get rid of the vertical header
642 m_pMaintable->verticalHeader()->hide(); // by hiding it with a margin of 0
643 m_pMaintable->horizontalHeader()->setResizeEnabled(true);
644 m_pMaintable->horizontalHeader()->setClickEnabled(true); // Allow click signals
645 m_pMaintable->horizontalHeader()->setTracking(false); // No continuous tracking
646 m_pMaintable->setColumnStretchable(TITRAQ_IDXTAIL - 1, true);
648 // Allow for user determined data sorting and use saved values
649 m_pMaintable->setSortcol((int)m_pPrefs->getNumber(TITRAQ_PREFSORTCOL, TITRAQ_DEFSORTCOL));
650 m_pMaintable->setSortdir(m_pPrefs->getBool(TITRAQ_PREFSORTDIR, TITRAQ_DEFSORTDIR));
651 m_pMaintable->setSorting(true);
653 // Table header row
654 m_pTablehead = m_pMaintable->horizontalHeader();
655 m_pMaintable->setHScrollBarMode(Q3ScrollView::AlwaysOff);
656 m_pTablehead->setLabel(TITRAQ_IDXSTATUS, QObject::trUtf8("Stat"),
657 m_pPrefs->getNumber(TITRAQ_PREFSTATCOLWIDTH, TITRAQ_DEFSTATCOLWIDTH));
658 m_pMaintable->setColumnReadOnly (TITRAQ_IDXSTATUS, true);
659 m_pTablehead->setLabel(TITRAQ_IDXLINE, QObject::trUtf8("Line"),
660 m_pPrefs->getNumber(TITRAQ_PREFLCOLWIDTH, TITRAQ_DEFLCOLWIDTH));
661 m_pMaintable->setColumnReadOnly (TITRAQ_IDXLINE, true);
662 m_pTablehead->setLabel(TITRAQ_IDXUSER, QObject::trUtf8("User"),
663 m_pPrefs->getNumber(TITRAQ_PREFUCOLWIDTH, TITRAQ_DEFUCOLWIDTH));
664 m_pTablehead->setLabel(TITRAQ_IDXGUID, QObject::trUtf8("GUID"),
665 m_pPrefs->getNumber(TITRAQ_PREFGCOLWIDTH, TITRAQ_DEFGCOLWIDTH));
666 m_pMaintable->setColumnReadOnly (TITRAQ_IDXGUID, true);
667 m_pTablehead->setLabel(TITRAQ_IDXCRC, QObject::trUtf8("CRC"),
668 m_pPrefs->getNumber(TITRAQ_PREFCCOLWIDTH, TITRAQ_DEFCCOLWIDTH));
669 m_pMaintable->setColumnReadOnly (TITRAQ_IDXCRC, true);
670 m_pTablehead->setLabel(TITRAQ_IDXREV, QObject::trUtf8("Rev"),
671 m_pPrefs->getNumber(TITRAQ_PREFREVCOLWIDTH, TITRAQ_DEFREVCOLWIDTH));
672 m_pMaintable->setColumnReadOnly (TITRAQ_IDXREV, true);
673 m_pTablehead->setLabel(TITRAQ_IDXDATE, QObject::trUtf8("Date"),
674 m_pPrefs->getNumber(TITRAQ_PREFDCOLWIDTH, TITRAQ_DEFDCOLWIDTH));
675 m_pTablehead->setLabel(TITRAQ_IDXSTART, QObject::trUtf8("Begin"),
676 m_pPrefs->getNumber(TITRAQ_PREFSTARTCOLWIDTH, TITRAQ_DEFSTARTCOLWIDTH));
677 m_pTablehead->setLabel(TITRAQ_IDXFINISH, QObject::trUtf8("End"),
678 m_pPrefs->getNumber(TITRAQ_PREFFCOLWIDTH, TITRAQ_DEFFCOLWIDTH));
679 m_pTablehead->setLabel(TITRAQ_IDXAMOUNT, QObject::trUtf8("Amount"),
680 m_pPrefs->getNumber(TITRAQ_PREFACOLWIDTH, TITRAQ_DEFACOLWIDTH));
681 m_pTablehead->setLabel(TITRAQ_IDXTASK, QObject::trUtf8("Task"),
682 m_pPrefs->getNumber(TITRAQ_PREFTCOLWIDTH, TITRAQ_DEFTCOLWIDTH));
683 m_pTablehead->setLabel(TITRAQ_IDXREMARK, QObject::trUtf8("Remark"));
685 m_pPackagelayout->addWidget(m_pMaintable); // Finally add the damn table
687 // Table update signals
688 connect(m_pMaintable, SIGNAL(currentChanged(int, int)), SLOT(updEdit(int, int)));
689 connect(m_pMaintable, SIGNAL(clicked(int, int, int, const QPoint&)), SLOT(onClick(int, int, int, const QPoint&)));
690 connect(m_pMaintable, SIGNAL(doubleClicked(int, int, int, const QPoint&)), SLOT(inplaceEdit(int, int, int, const QPoint&)));
691 connect(m_pTablehead, SIGNAL(sizeChange(int, int, int)), SLOT(updSizes(int, int, int)));
692 connect(m_pMaintable, SIGNAL(textEdited(int, int)), SLOT(dataChanged(int, int)));
693 connect(m_pMaintable, SIGNAL(valueChanged(int, int)), SLOT(dataChanged(int, int)));
694 }
696 //
697 // Construct the bottom edit widgets
698 //
699 void Titraqform::setupEditlay(void)
700 {
701 // QSpacerItem Pad(TITRAQ_SPACING / 2, 0, QSizePolicy::Fixed);
702 // m_pEditlayout->addWidget(&Pad); // Padd left side of control layout
704 // Make the status edit
705 m_pStatusedit = new QLabel(m_pCenframe, "Status");
706 if (m_pStatusedit == NULL) // Sanity check
707 throw Genexcept("Main window status edit creation failed.");
708 m_pStatusedit->setPixmap(QPixmap(s_kpcStatvoid_xpm)); // Placeholder
711 // Whatsthis info for the item status edit
712 const char *kszStatustext = "The <em>item status</em> shows a green "
713 "symbol for valid entries, a yellow symbol "
714 "for warning, and a red symbol for flawed entries.";
715 Q3WhatsThis::add(m_pStatusedit, kszStatustext);
716 QToolTip::add(m_pStatusedit, trUtf8("Status Indicator"));
717 m_pEditlayout->addWidget(m_pStatusedit); // Finally add the item status edit
719 // Make the line number edit
720 m_pLineedit = new QLineEdit(m_pCenframe, "Lineno");
721 if (m_pLineedit == NULL) // Sanity check
722 throw Genexcept("Main window line number edit creation failed.");
723 m_pLineedit->setFrameShape(QLineEdit::LineEditPanel);
724 m_pLineedit->setFrameShadow(QLineEdit::Sunken);
725 m_pLineedit->setFrame(true);
726 m_pLineedit->setReadOnly(true);
727 m_pLineedit->setEnabled(false);
728 m_pLineedit->setAlignment(Qt::AlignRight);
730 // Whatsthis info for the line number edit
731 const char *kszLinenotext = "The <em>line number</em> helps identify "
732 "an entry when a warning or error message "
733 "appears.";
734 Q3WhatsThis::add(m_pLineedit, kszLinenotext);
735 QToolTip::add(m_pLineedit, trUtf8("Line Number"));
736 m_pEditlayout->addWidget(m_pLineedit); // Finally add the line number edit
738 // Make the user edit
739 m_pUseredit = new QLineEdit(m_pCenframe, "User");
740 if (m_pUseredit == NULL) // Sanity check
741 throw Genexcept("Main window user edit creation failed.");
742 m_pUseredit->setFrameShape(QLineEdit::LineEditPanel);
743 m_pUseredit->setFrameShadow(QLineEdit::Sunken);
744 m_pUseredit->setFrame(true);
745 m_pUseredit->setReadOnly(false);
746 m_pUseredit->setEnabled(false);
748 // Whatsthis info for the user edit
749 const char *kszUsertext = "Edit the <em>user name</em> by clicking "
750 "on this control and typing the user name "
751 "you want to account.";
752 Q3WhatsThis::add(m_pUseredit, kszUsertext);
753 QToolTip::add(m_pUseredit, trUtf8("User Name"));
754 m_pEditlayout->addWidget(m_pUseredit); // Finally add the user edit
756 // Make the GUID edit
757 m_pGuidedit = new QLineEdit(m_pCenframe, "Guid");
758 if (m_pGuidedit == NULL) // Sanity check
759 throw Genexcept("Main window GUID edit creation failed.");
760 m_pGuidedit->setFrameShape(QLineEdit::LineEditPanel);
761 m_pGuidedit->setFrameShadow(QLineEdit::Sunken);
762 m_pGuidedit->setFrame(true);
763 m_pGuidedit->setReadOnly(true);
764 m_pGuidedit->setEnabled(false);
766 // Whatsthis info for the GUID edit
767 const char *kszGuidtext = "Edit the <em>GUID</em> by clicking "
768 "on this control and typing the GUID "
769 "corresponding to this account item.";
770 Q3WhatsThis::add(m_pGuidedit, kszGuidtext);
771 QToolTip::add(m_pGuidedit, trUtf8("GUID"));
772 m_pEditlayout->addWidget(m_pGuidedit); // Finally add the GUID edit
774 // Make the CRC edit
775 m_pCrcedit = new QLineEdit(m_pCenframe, "Crc");
776 if (m_pCrcedit == NULL) // Sanity check
777 throw Genexcept("Main window CRC edit creation failed.");
778 m_pCrcedit->setFrameShape(QLineEdit::LineEditPanel);
779 m_pCrcedit->setFrameShadow(QLineEdit::Sunken);
780 m_pCrcedit->setFrame(true);
781 m_pCrcedit->setReadOnly(true);
782 m_pCrcedit->setEnabled(false);
784 // Whatsthis info for the CRC edit
785 const char *kszCrctext = "Edit the <em>CRC</em> by clicking "
786 "on this control and typing the new "
787 "value for this account item.";
788 Q3WhatsThis::add(m_pCrcedit, kszCrctext);
789 QToolTip::add(m_pCrcedit, trUtf8("CRC"));
790 m_pEditlayout->addWidget(m_pCrcedit); // Finally add the CRC edit
792 // Make the revision edit
793 m_pRevedit = new QLineEdit(m_pCenframe, "Revision");
794 if (m_pRevedit == NULL) // Sanity check
795 throw Genexcept("Main window revision edit creation failed.");
796 m_pRevedit->setFrameShape(QLineEdit::LineEditPanel);
797 m_pRevedit->setFrameShadow(QLineEdit::Sunken);
798 m_pRevedit->setFrame(true);
799 m_pRevedit->setReadOnly(true);
800 m_pRevedit->setEnabled(false);
802 // Whatsthis info for the revision edit
803 const char *kszRevtext = "Edit the <em>revision</em> by clicking "
804 "on this control and typing the new value "
805 "for this account type.";
806 Q3WhatsThis::add(m_pRevedit, kszRevtext);
807 QToolTip::add(m_pRevedit, trUtf8("Revision"));
808 m_pEditlayout->addWidget(m_pRevedit); // Finally add the revision edit
810 // Make the date selector
811 m_pDateedit = new Daydatedit(QDate::currentDate(), m_pCenframe, "Date");
812 if (m_pDateedit == NULL) // Sanity check
813 throw Genexcept("Main window date edit creation failed."); // Spew errors
815 // Configure attributes
816 m_pDateedit->setOrder(Q3DateEdit::YMD);
817 m_pDateedit->setAutoAdvance(true);
818 m_pDateedit->setSeparator(trUtf8("-"));
819 m_pDateedit->setEnabled(false);
821 // Whatsthis info for the date editor
822 const char *kszDateedit = "Edit the <em>task date</em> by clicking on "
823 "the year, month, or day, and then changing their "
824 "values with the arrow buttons.";
825 Q3WhatsThis::add(m_pDateedit, kszDateedit);
826 QToolTip::add(m_pDateedit, trUtf8("Task Date"));
827 m_pEditlayout->addWidget(m_pDateedit); // Finally add the date editor
829 // Make the start time selector
830 m_pStarttime = new Q3TimeEdit(m_pCenframe, "StartTime");
831 if (m_pStarttime == NULL) // Sanity check
832 throw Genexcept("Main window start time creation failed."); // Spew errors
834 // Configure attributes
835 m_pStarttime->setDisplay(Q3TimeEdit::Hours | Q3TimeEdit::Minutes);
836 m_pStarttime->setAutoAdvance(true);
837 m_pStarttime->setEnabled(false);
839 // Whatsthis info for the time editor
840 const char *kszStarttime = "Edit the <em>task starting time</em> by clicking on "
841 "the hour and minute, and then changing their "
842 "values with the arrow buttons.";
843 Q3WhatsThis::add(m_pStarttime, kszStarttime);
844 QToolTip::add(m_pStarttime, trUtf8("Task Starting Time"));
845 m_pEditlayout->addWidget(m_pStarttime); // Finally add the start editor
847 // Make the end time selector
848 m_pEndtime = new Q3TimeEdit(m_pCenframe, "EndTime");
849 if (m_pEndtime == NULL) // Sanity check
850 throw Genexcept("Main window end time creation failed."); // Spew errors
852 // Configure attributes
853 m_pEndtime->setDisplay(Q3TimeEdit::Hours | Q3TimeEdit::Minutes);
854 m_pEndtime->setAutoAdvance(true);
855 m_pEndtime->setEnabled(false);
857 // Whatsthis info for the time editor
858 const char *kszEndtime = "Edit the <em>task ending time</em> by clicking on "
859 "the hour and minute, and then changing their "
860 "values with the arrow buttons.";
861 Q3WhatsThis::add(m_pEndtime, kszEndtime);
862 QToolTip::add(m_pEndtime, trUtf8("Task Ending Time"));
863 m_pEditlayout->addWidget(m_pEndtime); // Finally add the end editor
865 // // Make the total time amount selector
866 // m_pAmount = new QTimeEdit(m_pCenframe, "TotalAmount");
867 // if (m_pAmount == NULL) // Sanity check
868 // throw Genexcept("Main window amount creation failed."); // Spew errors
869 //
870 // // Configure attributes
871 // m_pAmount->setDisplay(QTimeEdit::Hours | QTimeEdit::Minutes);
872 // m_pAmount->setAutoAdvance(true);
873 // m_pAmount->setEnabled(false);
875 // Make the amount selector
876 m_pAmount = new ASTimeEdit(m_pCenframe, "TotalAmount");
877 if (m_pAmount == NULL) // Sanity check
878 throw Genexcept("Main window amount creation failed."); // Spew errors
880 // Whatsthis info for the amount editor
881 const char *kszAmount = "Edit the <em>task amount</em> by clicking on "
882 "the amount, and then changing its "
883 "value with the arrow buttons.";
884 Q3WhatsThis::add(m_pAmount, kszAmount);
885 QToolTip::add(m_pAmount, trUtf8("Task Amount"));
886 m_pAmount->setEnabled(false); // Don't enable until it's ready
887 m_pEditlayout->addWidget(m_pAmount); // Finally add the amount editor
889 // Construct a stringlist just to hold task values
890 m_pTaskentries = new QStringList;
891 if (m_pTaskentries == NULL) // Sanity check
892 throw Genexcept("Main window task entries creation failed.");
894 // Populate the stringlist with fresh accounts, taken from filename in prefs
895 QString Asdir = m_pPrefs->getString(TITRAQ_PREFACCOUNTS, TITRAQ_DEFACCOUNTS);
896 if (Asdir.startsWith(TITRAQ_HOMEDIRTOK))
897 Asdir = QDir::homeDirPath() + Asdir.remove(0, QString(TITRAQ_HOMEDIRTOK).length() - 1);
898 QFile Filetemp(Asdir);
899 this->loadAccounts(Filetemp); // Load account helper method
901 // Make the combobox task edit
902 m_pTasks = new Q3ComboBox(true, m_pCenframe, "Tasks");
903 if (m_pTasks == NULL) // Sanity check
904 throw Genexcept("Main window task edit creation failed.");
905 m_pTasks->insertStringList(*m_pTaskentries);
906 m_pTasks->setCurrentText(NULL);
907 m_pTasks->setSizeLimit(TITRAQ_ACCTBOXHEIGHT);
908 m_pTasks->setAutoCompletion(true);
909 m_pTasks->setDuplicatesEnabled(false);
910 m_pTasks->setEnabled(false);
911 // m_pTasks->setEditable(false); // Only idiots define noneditable and autocompletion
913 // Add an auto scroll bar if possible under current GUI style
914 if (m_pTasks->listBox()) { // Motif style has no list box
915 int nPopupwidth = m_pTasks->listBox()->maxItemWidth();
916 nPopupwidth += m_pTasks->listBox()->horizontalScrollBar()->height();
917 m_pTasks->listBox()->setFixedWidth(nPopupwidth);
918 m_pTasks->listBox()->setHScrollBarMode(Q3ScrollView::Auto);
919 m_pTasks->listBox()->sort();
920 }
922 // Whatsthis info for the task editor
923 const char *kszTasktext = "Choose a <em>task account</em> by clicking on "
924 "this box, and choosing whichever item most "
925 "closely resembles your task.";
926 Q3WhatsThis::add(m_pTasks, kszTasktext);
927 QToolTip::add(m_pTasks, trUtf8("Task Selector"));
928 m_pEditlayout->addWidget(m_pTasks); // Finally add the task edit
930 // Make the Remark line
931 m_pRemark = new QLineEdit(m_pCenframe, "Remark");
932 if (m_pRemark == NULL) // Sanity check
933 throw Genexcept("Main window remark line creation failed.");
934 m_pRemark->setFrameShape(QLineEdit::LineEditPanel);
935 m_pRemark->setFrameShadow(QLineEdit::Sunken);
936 m_pRemark->setFrame(true);
937 m_pRemark->setReadOnly(false);
938 m_pRemark->setEnabled(false);
940 // Whatsthis info for the remark line
941 const char *kszRemarktext = "Edit the <em>task remarks</em> by clicking on "
942 "this line control and typing the remarks you "
943 "have about the task.";
944 Q3WhatsThis::add(m_pRemark, kszRemarktext);
945 QToolTip::add(m_pRemark, trUtf8("Remark Line"));
946 m_pEditlayout->addWidget(m_pRemark); // Finally add the remark line
948 // Start edit controls off at right size
949 this->updSizes(TITRAQ_IDXALLCTRLS, -1, -1);
951 // Validate data just as it is being entered
952 connect(m_pDateedit, SIGNAL(valueChanged(const QDate &)), SLOT(validateRow(void)));
953 connect(m_pStarttime, SIGNAL(valueChanged(const QTime &)), SLOT(validateRow(void)));
954 connect(m_pEndtime, SIGNAL(valueChanged(const QTime &)), SLOT(validateRow(void)));
955 connect(m_pAmount, SIGNAL(valueChanged(const QTime &)), SLOT(validateRow(void)));
956 connect(m_pTasks, SIGNAL(textChanged(const QString &)), SLOT(validateRow(void)));
957 connect(m_pRemark, SIGNAL(textChanged(const QString &)), SLOT(validateRow(void)));
959 // Signals sent between table cells and corresponding edit control widgets
960 connect(m_pLineedit, SIGNAL(textChanged(const QString &)), SLOT(updateLine(const QString &)));
961 connect(m_pUseredit, SIGNAL(textChanged(const QString &)), SLOT(updateUser(const QString &)));
962 connect(m_pGuidedit, SIGNAL(textChanged(const QString &)), SLOT(updateGuid(const QString &)));
963 connect(m_pCrcedit, SIGNAL(textChanged(const QString &)), SLOT(updateCrc(const QString &)));
964 connect(m_pRevedit, SIGNAL(textChanged(const QString &)), SLOT(updateRev(const QString &)));
965 connect(m_pDateedit, SIGNAL(valueChanged(const QDate &)), SLOT(updateDate(const QDate &)));
966 connect(m_pStarttime, SIGNAL(valueChanged(const QTime &)), SLOT(updateStart(const QTime &)));
967 connect(m_pEndtime, SIGNAL(valueChanged(const QTime &)), SLOT(updateFinish(const QTime &)));
968 connect(m_pAmount, SIGNAL(valueChanged(const QTime &)), SLOT(updateAmount(const QTime &)));
969 connect(m_pTasks, SIGNAL(textChanged(const QString &)), SLOT(updateTask(const QString &)));
970 connect(m_pRemark, SIGNAL(textChanged(const QString &)), SLOT(updateRemark(const QString &)));
972 // Correctly update checksum and revision fields also
973 connect(m_pUseredit, SIGNAL(textChanged(const QString &)), SLOT(calcCrc(void)));
974 connect(m_pDateedit, SIGNAL(valueChanged(const QDate &)), SLOT(calcCrc(void)));
975 connect(m_pStarttime, SIGNAL(valueChanged(const QTime &)), SLOT(calcCrc(void)));
976 connect(m_pEndtime, SIGNAL(valueChanged(const QTime &)), SLOT(calcCrc(void)));
977 connect(m_pAmount, SIGNAL(valueChanged(const QTime &)), SLOT(calcCrc(void)));
978 connect(m_pTasks, SIGNAL(textChanged(const QString &)), SLOT(calcCrc(void)));
979 connect(m_pRemark, SIGNAL(textChanged(const QString &)), SLOT(calcCrc(void)));
980 }
982 //
983 // Arrange and configure columns
984 //
985 void Titraqform::setupColumns(void)
986 {
987 // Handle column view handling presets and defaults
988 if (!m_pPrefs->getBool(TITRAQ_PREFSTATCOLON, TITRAQ_DEFSTATCOLON))
989 showStatcol();
990 if (!m_pPrefs->getBool(TITRAQ_PREFLCOLON, TITRAQ_DEFLCOLON))
991 showLinecol();
992 if (!m_pPrefs->getBool(TITRAQ_PREFUCOLON, TITRAQ_DEFUCOLON))
993 showUsercol();
994 if (!m_pPrefs->getBool(TITRAQ_PREFGCOLON, TITRAQ_DEFGCOLON))
995 showGuidcol();
996 if (!m_pPrefs->getBool(TITRAQ_PREFCCOLON, TITRAQ_DEFCCOLON))
997 showCrccol();
998 if (!m_pPrefs->getBool(TITRAQ_PREFREVCOLON, TITRAQ_DEFREVCOLON))
999 showRevcol();
1000 if (!m_pPrefs->getBool(TITRAQ_PREFDCOLON, TITRAQ_DEFDCOLON))
1001 showDatecol();
1002 if (!m_pPrefs->getBool(TITRAQ_PREFSTARTCOLON, TITRAQ_DEFSTARTCOLON))
1003 showStartcol();
1004 if (!m_pPrefs->getBool(TITRAQ_PREFFCOLON, TITRAQ_DEFFCOLON))
1005 showFinishcol();
1006 if (!m_pPrefs->getBool(TITRAQ_PREFACOLON, TITRAQ_DEFACOLON))
1007 showAmountcol();
1008 if (!m_pPrefs->getBool(TITRAQ_PREFTCOLON, TITRAQ_DEFTCOLON))
1009 showTaskcol();
1010 if (!m_pPrefs->getBool(TITRAQ_PREFREMCOLON, TITRAQ_DEFREMCOLON))
1011 showRemarkcol();
1013 // Handle tool bar view handling presets and defaults
1014 if (!m_pPrefs->getBool(TITRAQ_PREFFILEBAR, TITRAQ_DEFFILEBAR)) {
1015 m_pFiletools->hide();
1016 m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXFILEBAR), false);
1017 }
1018 if (!m_pPrefs->getBool(TITRAQ_PREFEDITBAR, TITRAQ_DEFEDITBAR)) {
1019 m_pEdittools->hide();
1020 m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXEDITBAR), false);
1021 }
1022 if (!m_pPrefs->getBool(TITRAQ_PREFVIEWBAR, TITRAQ_DEFVIEWBAR)) {
1023 m_pViewtools->hide();
1024 m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXVIEWBAR), false);
1025 }
1026 if (!m_pPrefs->getBool(TITRAQ_PREFPREFBAR, TITRAQ_DEFPREFBAR)) {
1027 m_pPrefstools->hide();
1028 m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXPREFBAR), false);
1029 }
1030 if (!m_pPrefs->getBool(TITRAQ_PREFWHATBAR, TITRAQ_DEFWHATBAR)) {
1031 m_pWhatstools->hide();
1032 m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXWHATBAR), false);
1033 }
1034 }
1036 //
1037 // [En|dis]able most ui pieces to suit or restrict user
1038 //
1039 void Titraqform::enableIface(bool bTurned)
1040 {
1041 // FIXME: Does not belong here, so relocate
1042 if (bTurned) // Turn off the interface
1043 m_pDateedit->setDayfocus(); // Default focus is on day
1044 else { // Turn on the interface
1045 m_pMaintable->setNumRows(0); // Remove table data
1046 m_pStatusedit->setPixmap(QPixmap(s_kpcStatvoid_xpm));
1047 }
1049 // Enable or disable the widgets
1050 m_pMaintable->setEnabled(bTurned);
1051 m_pLineedit->setEnabled(bTurned);
1052 m_pUseredit->setEnabled(bTurned);
1053 m_pGuidedit->setEnabled(bTurned);
1054 m_pCrcedit->setEnabled(bTurned);
1055 m_pRevedit->setEnabled(bTurned);
1056 m_pDateedit->setEnabled(bTurned);
1057 m_pStarttime->setEnabled(bTurned);
1058 m_pEndtime->setEnabled(bTurned);
1059 m_pAmount->setEnabled(bTurned);
1060 m_pTasks->setEnabled(bTurned);
1061 m_pRemark->setEnabled(bTurned);
1063 // Enable or disable the actions
1064 m_pFilesaveact->setEnabled(bTurned);
1065 m_pFilesaveasact->setEnabled(bTurned);
1066 m_pFilecloseact->setEnabled(bTurned);
1067 m_pAddrowact->setEnabled(bTurned);
1068 m_pDelrowact->setEnabled(bTurned);
1069 m_pRefreshact->setEnabled(bTurned);
1070 m_pCutact->setEnabled(bTurned);
1071 m_pCopyact->setEnabled(bTurned);
1072 m_pPasteact->setEnabled(bTurned);
1073 m_pReportact->setEnabled(bTurned);
1074 #if defined HAVE_MICO || defined HAVE_ESOAP
1075 if (bTurned)
1076 m_pSyncact->setEnabled(m_pPrefs->getBool(TITRAQ_PREFCORBON, TITRAQ_DEFCORBON)
1077 | m_pPrefs->getBool(TITRAQ_PREFSOAPON, TITRAQ_DEFSOAPON));
1078 else
1079 m_pSyncact->setEnabled(false);
1080 #endif // defined HAVE_MICO || defined HAVE_ESOAP
1082 // Unconditional settings
1083 m_pMaintable->setDirty(false); // Reset to clean data
1084 }
1086 //
1087 // Parse command line arguments for an existing filename, and
1088 // open it to edit the intended (but optional) initial data
1089 //
1090 void Titraqform::loadInit(void)
1091 {
1092 // If the user gives a filename argument to the shell, then open that file
1093 int nNumargs = qApp->argc(); // Holds the number of cmd arguments
1094 int nValid = 0; // Holds the return value
1095 QFile Initial; // Initial event data file
1097 if (nNumargs > 1) { // Warm up a nice cascade, to set my mind on four weeks of vacation
1098 for (int nIter = 1; nIter < nNumargs; nIter++) { // Salad in New Zealand
1099 if (QChar(*qApp->argv()[nIter]) != '-') { // Bunuelos in Colombia
1100 try {
1101 this->setFilename(qApp->argv()[nIter]); // Store inital filename
1102 Initial.setName(*this->getFilename()); // Initial file to load
1103 if (Initial.exists(*getFilename()) && validateData(Initial)) {
1104 this->loadData(Initial); // Pass to helper method
1105 enableIface(true); // Turn on the lights
1106 m_pStatbar->message(trUtf8("Loaded document ") + *this->getFilename());
1107 }
1108 else // The inital file name does not correspond to a file
1109 m_pStatbar->message(trUtf8(QString("The file ") + *this->getFilename() + QString(" does not exist.")));
1110 }
1111 catch (Genexcept& Genex) {
1112 Genex.reportErr();
1113 }
1114 }
1115 }
1116 }
1117 else
1118 m_pStatbar->message(trUtf8("Ready")); // Signal a ready condition
1119 }