OSSP CVS Repository

ossp - Check-in [2826]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2826
Date: 2002-Nov-14 19:19:29 (local)
2002-Nov-14 18:19:29 (UTC)
User:ms
Branch:
Comment: Add actions, corresponding slots, use new bitmaps, add a toolbar, begin coding of data serialization logic.
Tickets:
Inspections:
Files:
ossp-pkg/as/as-gui/TODO      1.5 -> 1.6     2 inserted, 0 deleted
ossp-pkg/as/as-gui/as_gui.cpp      1.6 -> 1.7     234 inserted, 26 deleted
ossp-pkg/as/as-gui/as_gui.h      1.5 -> 1.6     20 inserted, 0 deleted
ossp-pkg/titraq/TODO      1.5 -> 1.6     2 inserted, 0 deleted
ossp-pkg/titraq/titraq.cpp      1.6 -> 1.7     234 inserted, 26 deleted
ossp-pkg/titraq/titraq.h      1.5 -> 1.6     20 inserted, 0 deleted

ossp-pkg/as/as-gui/TODO 1.5 -> 1.6

--- TODO 2002/11/13 16:36:58     1.5
+++ TODO 2002/11/14 18:19:29     1.6
@@ -14,6 +14,8 @@
 Q_CHECK_PTR
 public/private
 QWhatsThis::add(m_pAddbutton, trUtf8("Para soltar la pepa"));
+configure soll ueberpruefen ob libqt[-mt] threads braucht,
+  dann wenn so, soll den LIBS -pthread hardgecodet haben
 
 Dreams
 ------


ossp-pkg/as/as-gui/as_gui.cpp 1.6 -> 1.7

--- as_gui.cpp   2002/11/13 16:36:58     1.6
+++ as_gui.cpp   2002/11/14 18:19:29     1.7
@@ -1,19 +1,25 @@
 // System interface
 #include <qtooltip.h>
+#include <qwhatsthis.h>
 #include <qdatetimeedit.h>
 #include <qspinbox.h>
 #include <qstringlist.h>
 #include <qcombobox.h>
 #include <qcursor.h>
+#include <qfile.h>
+#include <qfiledialog.h>
 
 // User interface
 #include "titraq.h"         // Main classes
 #include "generic.h"        // Generic classes
-#include "gfx/ossplogo.xpm" // OSSP logo: static const char *ossplogo_xpm[]
+#include "gfx/ossplogo.xpm" // OSSP logo: static const char *s_kpcOssplogo_xpm[]
+#include "gfx/fileopen.xpm" // static const char *s_kpcFileopen_xpm[]
+#include "gfx/filesave.xpm" // static const char *s_kpcFilesave_xpm[]
 
-// Used in initialization of the application
+// Overload init for custom initialization of the app
 void Titraqform::init(void)
 {
+    // Set fill color of buttons
     m_pAddbutton->setPaletteBackgroundColor(QColor(196, 196, 176));
     m_pDeletebutton->setPaletteBackgroundColor(QColor(196, 196, 176));
     m_pWritebutton->setPaletteBackgroundColor(QColor(196, 196, 176));
@@ -36,38 +42,87 @@
     m_pMenubar = this->menuBar();
     m_pStatbar = this->statusBar();
     m_pStatbar->message(trUtf8("Ready"));
-    setCaption(trUtf8("OSSP Titraq"));
+    setCaption("OSSP Titraq");
 
-    // Lock down window size
-    setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0,
-        (QSizePolicy::SizeType)0, 0, 0, sizePolicy().hasHeightForWidth()));
+    // File new action
+    m_pFilenewact = new QAction(trUtf8("New"), trUtf8("&New"), CTRL+Key_N, this, "New");
+    connect(m_pFilenewact, SIGNAL(activated()), this, SLOT(newDoc()));
+
+    // File open action
+    m_pFileopenact = new QAction(trUtf8("Open File"), QPixmap(s_kpcFileopen_xpm), trUtf8("&Open"), CTRL+Key_O, this, "Open");
+    connect(m_pFileopenact, SIGNAL(activated()), this, SLOT(choose()));
+    const char *kszFileopentext = trUtf8("<p><img source=\"fileopen\"> "
+                                  "Click this button to open a <em>new file</em>.<br>"
+                                  "You can also select the <b>Open</b> command "
+                                  "from the <b>File</b> menu.</p>");
+    QMimeSourceFactory::defaultFactory()->setPixmap("fileopen", m_pFileopenact->iconSet().pixmap());
+    m_pFileopenact->setWhatsThis(kszFileopentext);
+
+    // File save current action
+    m_pFilesaveact = new QAction(trUtf8("Save File"), QPixmap(s_kpcFilesave_xpm), trUtf8("&Save"), CTRL+Key_S, this, "Save");
+    connect(m_pFilesaveact, SIGNAL(activated()), this, SLOT(save()));
+    const char *kszFilesavetext = trUtf8("<p>Click this button to save the file you "
+                                  "are editing. You will be prompted for a file name.\n"
+                                  "You can also select the <b>Save</b> command "
+                                  "from the <b>File</b> menu.</p>");
+    m_pFilesaveact->setWhatsThis(kszFilesavetext);
+
+    // File save selected action
+    m_pFilesaveasact = new QAction(trUtf8("Save File As"), trUtf8("Save &as"), 0, this, "SaveAs");
+    connect(m_pFilesaveasact, SIGNAL(activated()), this, SLOT(saveAs()));
+    m_pFilesaveasact->setWhatsThis(kszFilesavetext);
+
+    // File close current action
+    m_pFilecloseact = new QAction(trUtf8("Close"), trUtf8("&Close"), CTRL+Key_W, this, "Close");
+    connect(m_pFilecloseact, SIGNAL(activated()), this, SLOT(close()));
+
+    // File quit action
+    m_pFilequitact = new QAction(trUtf8("Quit"), trUtf8("&Quit"), CTRL+Key_Q, this, "Quit");
+    connect(m_pFilequitact, SIGNAL(activated()), qApp, SLOT(quit()));
+
+//    // Lock down window size
+//    setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0,
+//        (QSizePolicy::SizeType)0, 0, 0, sizePolicy().hasHeightForWidth()));
 
-    // Work on the menu bar
+    // Construct and populate the file menu with actions
     QPopupMenu *pFilepopup = new QPopupMenu(this);
-    m_pMenubar->insertItem("&File", pFilepopup);
-//    pFilepopup->insertItem("&Quit", this, SLOT(quit()));
-//    pFilenewact->addTo(pFilepopup);
-//    pFileopenact->addTo(pFilepopup);
-//    pFilesaveact->addTo(pFilepopup);
+    m_pMenubar->insertItem(trUtf8("&File"), pFilepopup);
+    m_pFilenewact->addTo(pFilepopup);
+    m_pFileopenact->addTo(pFilepopup);
+    m_pFilesaveact->addTo(pFilepopup);
+    m_pFilesaveasact->addTo(pFilepopup);
+    pFilepopup->insertSeparator();
+    m_pFilecloseact->addTo(pFilepopup);
+    m_pFilequitact->addTo(pFilepopup);
+
+    // Construct and populate the help menu with subitems
+    QPopupMenu *pHelppopup = new QPopupMenu(this);
+    m_pMenubar->insertItem(trUtf8("&Help"), pHelppopup);
+    pHelppopup->insertItem(trUtf8("&About"), this, SLOT(about()), Key_F1);
+    pHelppopup->insertItem(trUtf8("About &Qt"), this, SLOT(aboutQt()));
+    pHelppopup->insertSeparator();
+    pHelppopup->insertItem(trUtf8("What's &This"), this, SLOT(whatsThis()), SHIFT+Key_F1);
 
-    // Make a new tool bar
+    // Construct and populate the main tool bar
     m_pToolbar = new QToolBar("Toolfile", this, DockTop);
     m_pToolbar->setLabel(trUtf8("File Ops"));
-//    pFilenewact->addTo(m_pToolbar);
-//    pFileopenact->addTo(m_pToolbar);
-//    pFilesaveact->addTo(m_pToolbar);
+    m_pFileopenact->addTo(m_pToolbar);
+    m_pFilesaveact->addTo(m_pToolbar);
+
+    // Add a preconfigured whats this button to our new tool bar
+    QWhatsThis::whatsThisButton(m_pToolbar);
 
     // Create a central frame and associated layout for QMainWindow
     m_pCenframe = new QFrame(this);
     setCentralWidget(m_pCenframe);
 
     // Control layouts for form, table, and status line
-    m_pTitraqformlayout = new QVBoxLayout(m_pCenframe, 11, 6, "pTitraqformlayout");
-    m_pMainlayout = new QVBoxLayout(0, 0, 6, "pMainlayout");        // For layouts
-    m_pPackagelayout = new QVBoxLayout(0, 0, 6, "pPackagelayout");  // For table
+    m_pTitraqformlayout = new QVBoxLayout(m_pCenframe, 11, 6, "Titraqformlayout");
+    m_pMainlayout = new QVBoxLayout(0, 0, 6, "Mainlayout");         // For layouts
+    m_pPackagelayout = new QVBoxLayout(0, 0, 6, "Packagelayout");   // For table
 
     // The table itself
-    m_pMaintable = new QTable(this, "pMaintable");
+    m_pMaintable = new QTable(this, "Maintable");
     m_pMaintable->setNumRows(g_knRows);
     m_pMaintable->setNumCols(g_knCols);
     m_pMaintable->setReadOnly(false);                   // Not read only
@@ -89,7 +144,7 @@
     m_pTablehead->setMovingEnabled(true);
 
     // Icon image items
-    m_pIconimage = new QImage(ossplogo_xpm);
+    m_pIconimage = new QImage(s_kpcOssplogo_xpm);
     m_pIconpixmap = new QPixmap(m_pIconimage->scaleHeight(m_pMaintable->rowHeight(6)));
     m_pMaintable->setItem(0, 0, new QTableItem(m_pMaintable, QTableItem::Never, "OSSP trac"));
     m_pMaintable->setPixmap(0, 0, *m_pIconpixmap);
@@ -165,7 +220,7 @@
     m_pPackagelayout->addWidget(m_pMaintable);  // Finally add the table widget
 
     // Bottom output line
-    m_pStatus = new QLineEdit(this, "pStatus");
+    m_pStatus = new QLineEdit(this, "Status");
     m_pStatus->setFrameShape(QLineEdit::LineEditPanel);
     m_pStatus->setFrameShadow(QLineEdit::Sunken);
     m_pStatus->setFrame(true);
@@ -175,7 +230,7 @@
     m_pMainlayout->addLayout(m_pPackagelayout);
 
     // Control layout for push buttons
-    m_pControllayout = new QHBoxLayout(0, 0, 6, "pControllayout");  // For buttons
+    m_pControllayout = new QHBoxLayout(0, 0, 6, "Controllayout");  // For buttons
 
     // Tuple push button add
     m_pAddbutton = new QPushButton(this, "AddButton");
@@ -186,7 +241,7 @@
     m_pControllayout->addWidget(m_pAddbutton);
 
     // Tuple push button delete
-    m_pDeletebutton = new QPushButton(this, "pDeletebutton");
+    m_pDeletebutton = new QPushButton(this, "Deletebutton");
     m_pDeletebutton->setCursor(QCursor(13));
     m_pDeletebutton->setText(trUtf8("&Delete"));
     m_pDeletebutton->setFlat(false);
@@ -195,7 +250,7 @@
     m_pControllayout->addWidget(m_pDeletebutton);
 
     // Tuple push button write
-    m_pWritebutton = new QPushButton(this, "pWritebutton");
+    m_pWritebutton = new QPushButton(this, "Writebutton");
     m_pWritebutton->setCursor(QCursor(13));
     m_pWritebutton->setText(trUtf8("&Write"));
     QToolTip::add(m_pWritebutton, trUtf8("Write Entry"));
@@ -203,7 +258,7 @@
     m_pControllayout->addWidget(m_pWritebutton);
 
     // Tuple push button quit
-    m_pQuitbutton = new QPushButton(this, "pQuitbutton");
+    m_pQuitbutton = new QPushButton(this, "Quitbutton");
     m_pQuitbutton->setCursor(QCursor(13));
     m_pQuitbutton->setText(trUtf8("&Quit"));
     m_pQuitbutton->setFlat(false);
@@ -217,6 +272,9 @@
     init(); // Initialize signal and slot connections
 }
 
+//
+// Add a blank row entry to the current data window
+//
 void Titraqform::addEntry(void)
 {
     Prototype Unimp;
@@ -230,12 +288,18 @@
 //    }
 }
 
+//
+// Choose a file using a handy file dialog
+//
 void Titraqform::delEntry(void)
 {
     Prototype Unimp;
     Unimp.doMbox();
 }
 
+//
+// Write current data to a meta device
+//
 void Titraqform::writeEntry(void)
 {
     Prototype Unimp;
@@ -243,6 +307,150 @@
 }
 
 //
+// Make and display a new document window
+//
+void Titraqform::newDoc(void)
+{
+    Prototype Unimp;
+    Unimp.doMbox();
+//    Titraqform *pNewform = new Titraqform;
+//    pNewform->show();
+}
+
+//
+// Choose a file using a handy file dialog
+//
+void Titraqform::choose(void)
+{
+    QString Filestring = QFileDialog::getOpenFileName(QString::null, QString::null, this);
+    if (!Filestring.isEmpty())
+        load(Filestring);
+    else
+        m_pStatbar->message(trUtf8("Loading aborted"), 4000);
+}
+
+//
+// Load accounting data into main window
+//
+void Titraqform::load(const QString &Filestring)
+{
+    QFile Filetemp(Filestring);         // File to load
+
+    if (!Filetemp.open(IO_ReadOnly))    // Need a wrapped exception here
+        return;
+
+    QTextStream Textstream(&Filetemp);  // Convert the file contents to a stream
+    m_pStatus->setText(Textstream.read());
+    m_pStatus->setEdited(FALSE);
+    setCaption(Filestring);
+    m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000);
+}
+
+//
+// Serialize current state to the current file
+//
+void Titraqform::save(void)
+{
+    // First time saves are really just saveAs in disguise
+    if (m_szFilename->isEmpty()) {
+        saveAs();
+        return;
+    }
+
+    // Try to read the status text, and write it to a file
+    QString Statustext = m_pStatus->text();
+    QFile Filetemp(*m_szFilename);
+    if (!Filetemp.open(IO_WriteOnly)) {
+        m_pStatbar->message(QString(trUtf8("Could not write to %1")).arg(*m_szFilename), 4000);
+        return;
+    }
+
+    // Serialize file contents and write to text line
+    QTextStream Filestream(&Filetemp);
+    Filestream << Statustext;
+    Filetemp.close();
+
+    // Reset the text line, and give output to main window
+    m_pStatus->setEdited(FALSE);
+    setCaption(*m_szFilename);
+    m_pStatbar->message(QString(trUtf8("File %1 saved")).arg(*m_szFilename), 4000);
+}
+
+//
+// Serialize current state to a selected file
+//
+void Titraqform::saveAs(void)
+{
+    // First get the selected file name to save to
+    QString Filestring = QFileDialog::getSaveFileName(QString::null, QString::null, this);
+    if (!Filestring.isEmpty()) {
+        *m_szFilename = Filestring;
+        save(); // Finish off by calling the save action
+    }
+    else {
+        // User did not select a valid file and push okay button
+        m_pStatbar->message(trUtf8("Saving aborted"), 4000);
+    }
+}
+
+//
+// Close current document, displaying in main window
+//
+void Titraqform::closeEvent(QCloseEvent *pClosit)
+{
+    // Check modification state of current data
+    if (!this->isDirty()) {
+        pClosit->accept();
+        return;
+    }
+
+    // Ask user to aknowlege a possibly data-damaging close event
+    switch(QMessageBox::information(this, "OSSP titraq",
+        trUtf8("The document has been\nchanged since the last save.")),
+        trUtf8("Save Now"), trUtf8("Cancel"), trUtf8("Leave Anyway"), 0, 1) {
+    case 0:
+        save();
+        pClosit->accept();
+        break;
+    case 1:
+        default:    // Just for sanity
+        pClosit->ignore();
+        break;
+    case 2:
+        pClosit->accept();
+        break;
+    }
+}
+
+//
+// Check to see if state has changed since last save
+//
+bool Titraqform::isDirty(void)
+{
+    // FIXME: We're really not THAT dirty
+    return true;
+}
+
+//
+// Learn more about this program itself
+//
+void Titraqform::about(void)
+{
+    QMessageBox::about(this, "OSSP titraq",
+        trUtf8("OSSP titraq is a time and task-based\n"
+               "accounting system that acts as both a\n"
+               "nwork-like punch card and time tracker."));
+}
+
+//
+// Learn more about this program and Qt
+//
+void Titraqform::aboutQt(void)
+{
+    QMessageBox::aboutQt(this, "OSSP titraq");
+}
+
+//
 // Destroy the object and free any allocated resources
 //
 Titraqform::~Titraqform(void)


ossp-pkg/as/as-gui/as_gui.h 1.5 -> 1.6

--- as_gui.h     2002/11/13 16:36:58     1.5
+++ as_gui.h     2002/11/14 18:19:29     1.6
@@ -3,6 +3,7 @@
 
 #include <qapplication.h>
 #include <qmainwindow.h>
+#include <qaction.h>
 #include <qtable.h>
 #include <qmenubar.h>
 #include <qtoolbar.h>
@@ -26,6 +27,11 @@
     Titraqform(QWidget *pParent = 0, const char *kszName = 0, WFlags Flags = 0);
     ~Titraqform();
 
+    // Main application actions
+    QAction     *m_pFilenewact,   *m_pFileopenact;
+    QAction     *m_pFilesaveact,  *m_pFilesaveasact;
+    QAction     *m_pFilecloseact, *m_pFilequitact;
+
     // Table, cells, and entries in package layout
     QTable      *m_pMaintable;
     QHeader     *m_pTablehead;
@@ -47,8 +53,19 @@
     void addEntry(void);                // Add a task entry to the list
     void delEntry(void);                // Delete a task entry from the list
     void writeEntry(void);              // Write the task list to a filedescriptor
+    void newDoc(void);                  // Make and display a new document window
+    void choose(void);                  // Choose a file using a handy file dialog
+    void load(const QString &);         // Load accounting data into main window
+    void save(void);                    // Serialize to the current file
+    void saveAs(void);                  // Serialize to a selected file
+    void about(void);                   // Learn more about this program itself
+    void aboutQt(void);                 // Learn more about this program and Qt
 
 protected:
+    // Application main events
+    void closeEvent(QCloseEvent *);     // Close current document in main window
+
+    // Application main window widgets
     QFrame      *m_pCenframe;           // Central frame
     QVBoxLayout *m_pTitraqformlayout;   // Main form layout
     QVBoxLayout *m_pMainlayout;         // Package and control layouts
@@ -60,6 +77,9 @@
     QMenuBar    *m_pMenubar;
     QToolBar    *m_pToolbar;
     QStatusBar  *m_pStatbar;
+    QString     *m_szFilename;
+
+    bool isDirty(void);                 // Check for changed state danger
 };
 
 #endif // TITRAQMWIN_H




CVSTrac 2.0.1