OSSP CVS Repository

ossp - ossp-pkg/as/as-gui/as_slot.cpp 1.27
Not logged in
[Honeypot]  [Browse]  [Directory]  [Home]  [Login
[Reports]  [Search]  [Ticket]  [Timeline
  [Raw

ossp-pkg/as/as-gui/as_slot.cpp 1.27
// Qt headers
#include <qfiledialog.h>
#include <qcombobox.h>
#include <qregexp.h>

// User interface
#include "titraq.h"             // Main classes
#include "titrex.h"             // Exception classes
#include "titabitem.h"          // For our custom table items
#include "generic.h"            // Generic classes

// Icon pixel maps
#include "gfx/cwlogo.xpm"       // static const char *s_kpcCwlogo_xpm[]
#include "gfx/ossplogo.xpm"     // static const char *s_kpcOssplogo_xpm[]


//
// Cut an entry
//
void Titraqform::cutEntry(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// Copy an entry
//
void Titraqform::copyEntry(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// Paste an entry
//
void Titraqform::pasteEntry(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// Append a blank row entry
//
void Titraqform::addEntry(void)
{
    // Add a row after selection and focus to the new row
    if (m_pMaintable->currentRow() + 1 != m_pMaintable->numRows()) {
        m_pMaintable->insertRows(m_pMaintable->currentRow());
        m_pMaintable->setCurrentCell(m_pMaintable->currentRow() - 3, m_pMaintable->currentColumn());
    }
    else // Special case to handle adding an only row or last row
        m_pMaintable->insertRows(m_pMaintable->currentRow() + 1); {
        m_pMaintable->setCurrentCell(m_pMaintable->currentRow() + 1, m_pMaintable->currentColumn());
    }
}

//
// Delete a row entry
//
void Titraqform::delEntry(void)
{
    // Remove the row at selection and focus to the next row
    if (m_pMaintable->currentRow() + 1 != m_pMaintable->numRows()) {
        m_pMaintable->setCurrentCell(m_pMaintable->currentRow() + 1, m_pMaintable->currentColumn());
        m_pMaintable->removeRow(m_pMaintable->currentRow() - 1);
    }
    else // Special case to handle removing of only row or last row
        m_pMaintable->removeRow(m_pMaintable->currentRow());
}

//
// Make and display a new document window
//
void Titraqform::newDoc(void)
{
    m_pMaintable->setNumRows(0); // Get rid of any data in table
}

//
// Choose a file using a handy file dialog
//
void Titraqform::chooseFile(void)
{
    QString Filestring = QFileDialog::getOpenFileName("/e/dev/as", QString::null, this, trUtf8("Chooser Dialog"), trUtf8("Choose a file to open"));
    if (!Filestring.isEmpty()) {
        m_szFilename->operator=(Filestring);
        m_pMaintable->setNumRows(0);    // Clear out old data
        QFile Filetemp(Filestring);     // File to load
        try {
            loadData(Filetemp);         // Pass to helper method
        }
        catch (Genexcept& Genex) {
            Genex.reportErr();
        }
        // Reset and give output to main window
        this->setCaption(Filestring);
        m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000);
        this->setDirty(false);          // Set the clean state
    }
    else
        m_pStatbar->message(trUtf8("Loading aborted"), 4000);
}

//
// Serialize current state to the current file
//
void Titraqform::saveFile(void)
{
    // First time saves are really just saveAs in disguise
    if (m_szFilename->isEmpty()) {
        saveAs();
        return;
    }

    // Try to open a file for writing to
    QFile Filetemp(*m_szFilename);
    try {
        saveData(Filetemp); // Pass to helper method
    }
    catch (Genexcept& Genex) {
        Genex.reportErr();
    }
    // Reset and give output to main window
    this->setCaption(*m_szFilename);
    m_pStatbar->message(trUtf8("File %1 saved").arg(*m_szFilename), 4000);
    this->setDirty(false);  // Set the clean state to allow close
}

//
// 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;
        saveFile(); // 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 acknowlege 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:
        saveFile();
        pClosit->accept();
        break;
    case 1:
        default:    // Just for sanity
        pClosit->ignore();
        break;
    case 2:
        pClosit->accept();
        break;
    }
}

//
// Edit menu select all entries
//
void Titraqform::selAll(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// Edit a table entry in place, without the usual edit controls
//
void Titraqform::inplaceEdit(int nRow, int nCol, int nButton, const QPoint &Mousepos)
{
    m_pMaintable->setReadOnly(false);
    m_pMaintable->editCell(nRow, nCol);
    m_pMaintable->setReadOnly(true);
}

//
// Update the edit controls widget sizes
//
void Titraqform::updSizes(int nSection, int nOldsize, int nNewsize)
{
    switch (nSection) {
    case TITRAQ_IDXALLCTRLS:
        m_pDateedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXDATE) - TITRAQ_SPACING + TITRAQ_SPACING / 2);
        m_pStarttime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTART) - TITRAQ_SPACING);
        m_pEndtime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXFINISH) - TITRAQ_SPACING);
        m_pAmount->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXAMOUNT) - TITRAQ_SPACING);
        m_pTasks->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXTASK) - TITRAQ_SPACING);
//        m_pRemark->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXREMARK) - TITRAQ_SPACING);
        break;
    case TITRAQ_IDXDATE:
        m_pDateedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXDATE) - TITRAQ_SPACING + TITRAQ_SPACING / 2);
        break;
    case TITRAQ_IDXSTART:
        m_pStarttime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTART) - TITRAQ_SPACING);
        break;
    case TITRAQ_IDXFINISH:
        m_pEndtime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXFINISH) - TITRAQ_SPACING);
        break;
    case TITRAQ_IDXAMOUNT:
        m_pAmount->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXAMOUNT) - TITRAQ_SPACING);
        break;
    case TITRAQ_IDXTASK:
        m_pTasks->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXTASK) - TITRAQ_SPACING);
        break;
    case TITRAQ_IDXREMARK:
//        m_pRemark->setFixedWidth(nNewsize);
        break;
    default:
        throw Genexcept("Unrecognized main window column header.");
        break;
    }
}

//
// Update the edit controls contents
//
void Titraqform::updEdit(int nRow, int nCol)
{
    QRegExp Shorten("/(\\w+)$");    // For stripping prefix off the current task

    // Field strings to check for validity and process
    QString Textdate(m_pMaintable->text(nRow, TITRAQ_IDXDATE));
    QString Textstart(m_pMaintable->text(nRow, TITRAQ_IDXSTART));
    QString Textfinish(m_pMaintable->text(nRow, TITRAQ_IDXFINISH));
    QString Textamount(m_pMaintable->text(nRow, TITRAQ_IDXAMOUNT));
    QString Texttask(m_pMaintable->text(nRow, TITRAQ_IDXTASK));
    QString Textremark(m_pMaintable->text(nRow, TITRAQ_IDXREMARK));

    if (!Textdate.isEmpty())
        m_pDateedit->setDate(QDate::fromString(Textdate, Qt::ISODate));
    else
        m_pDateedit->setDate(*m_pDatezero);

    if (!Textstart.isEmpty())
        m_pStarttime->setTime(QTime::fromString(Textstart, Qt::ISODate));
    else
        m_pStarttime->setTime(QTime::QTime(0, 0));

    if (!Textfinish.isEmpty())
        m_pEndtime->setTime(QTime::fromString(Textfinish, Qt::ISODate));
    else
        m_pEndtime->setTime(QTime::QTime(0, 0));

    m_pAmount->setText(Textamount);

    // Process the task combo box to compress text length
    Texttask.remove(0, Shorten.search(Texttask) + 1); // Strip leading slash
    m_pTasks->setCurrentText(Texttask);

    m_pRemark->setText(Textremark);
}

//
// Confirm any recent editions on a whole row
//
void Titraqform::confirmEdit(void)
{
    // Conversions from edit control data formats to native tabular format
    m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXDATE, m_pDateedit->date().toString(Qt::ISODate));
    m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXSTART, m_pStarttime->time().toString(Qt::ISODate));
    m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXFINISH, m_pEndtime->time().toString(Qt::ISODate));
    m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXAMOUNT, m_pAmount->text());
    m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXTASK, m_pTasks->currentText());
    m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXREMARK, m_pRemark->text());
}

//
// Edit menu configure preferences
//
void Titraqform::configPrefs(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// View menu editing
//
void Titraqform::editingView(void)
{
    // All other view types are disabled until implemention, so this
    // body can remain empty, causing nothing to happen on selection.
}

//
// View menu timing
//
void Titraqform::timingView(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// View menu show file toolbar
//
void Titraqform::showFilebar(void)
{
    if (m_pFiletools->isVisible()) {
        m_pFiletools->hide();
        m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXFILEBAR), false);
    }
    else {
        m_pFiletools->show();
        m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXFILEBAR), true);
    }
}

//
// View menu show edit toolbar
//
void Titraqform::showEditbar(void)
{
    if (m_pEdittools->isVisible()) {
        m_pEdittools->hide();
        m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXEDITBAR), false);
    }
    else {
        m_pEdittools->show();
        m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXEDITBAR), true);
    }
}

//
// View menu show whats this toolbar
//
void Titraqform::showWhatsbar(void)
{
    if (m_pWhatstools->isVisible()) {
        m_pWhatstools->hide();
        m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXWHATBAR), false);
    }
    else {
        m_pWhatstools->show();
        m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXWHATBAR), true);
    }
}

//
// View menu show line numbers column
//
void Titraqform::showLinecol(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// View menu show GUIDs column
//
void Titraqform::showGuidcol(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// View menu show Dates column
//
void Titraqform::showDatecol(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// View menu show Users column
//
void Titraqform::showUsercol(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// View menu show Tasks column
//
void Titraqform::showTaskcol(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// View menu show Start time column
//
void Titraqform::showStartcol(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// View menu show Finish time column
//
void Titraqform::showFinishcol(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// View menu show Amounts column
//
void Titraqform::showAmountcol(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// View menu show Remarks column
//
void Titraqform::showRemarkcol(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// Get help on Titraq functionality
//
void Titraqform::helpContents(void)
{
    Prototype Unimp;
    Unimp.doMbox();
}

//
// Learn more about this program itself
//
void Titraqform::aboutTitraq(void)
{
    QMessageBox *pCwmsg = new QMessageBox("OSSP titraq",
        QObject::trUtf8("OSSP titraq is a time and task-based\n"
               "accounting system that acts as both a\n"
               "work-like punch card and time tracker.\n"
               "Development of titraq is sponsored by\n"
               "Cable & Wireless Deutschland GmbH."),
        QMessageBox::NoIcon, QMessageBox::Ok | QMessageBox::Default,
        QMessageBox::NoButton, QMessageBox::NoButton,
        NULL, "Titraqmessage", true, Qt::WStyle_NormalBorder);

    pCwmsg->setIconPixmap(QPixmap(s_kpcCwlogo_xpm));
    pCwmsg->exec();
}

//
// Learn more about the OSSP
//
void Titraqform::aboutOSSP(void)
{
    QMessageBox *pOsspmsg = new QMessageBox("OSSP titraq",
        QObject::trUtf8("The open source software project (OSSP) is\n"
               "a collective effort aimed at implementing\n"
               "high-quality Unix software components,\n"
               "ranging from networking, multi-threading\n"
               "and algorithmic libraries to networking\n"
               "servers and development tools."),
        QMessageBox::NoIcon, QMessageBox::Ok | QMessageBox::Default,
        QMessageBox::NoButton, QMessageBox::NoButton,
        NULL, "Osspmessage", true, Qt::WStyle_NormalBorder);

    pOsspmsg->setIconPixmap(QPixmap(s_kpcOssplogo_xpm));
    pOsspmsg->exec();
}

//
// Learn more about this program and Qt
//
void Titraqform::aboutQt(void)
{
    QMessageBox::aboutQt(this, "OSSP titraq");
}

CVSTrac 2.0.1