[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/utils/charm/trunk
From: David Faure <faure () kde ! org>
Date: 2008-01-03 12:08:53
Message-ID: 1199362133.506933.798.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 756534 by dfaure:
Show total hours for today and for this week in the statusbar.
CCMAIL: mirko@kde.org
M +43 -1 Charm/MainWindow.cpp
M +6 -0 Charm/MainWindow.h
M +0 -1 Core/CharmConstants.h
--- trunk/playground/utils/charm/trunk/Charm/MainWindow.cpp #756533:756534
@@ -3,6 +3,7 @@
#include <QSettings>
#include <QFileDialog>
#include <QMessageBox>
+#include <QStatusBar>
#include <Core/CharmCommand.h>
#include <Core/CharmConstants.h>
@@ -136,6 +137,10 @@
menuBar()->addMenu( appMenu );
menuBar()->addMenu( viewMenu );
+ // status bar:
+ statusBar()->addPermanentWidget( &m_statusBarLabelDayTotal );
+ statusBar()->addPermanentWidget( &m_statusBarLabelWeekTotal );
+
// system tray icon:
m_trayIcon.setIcon( Data::charmIcon() );
m_trayIcon.show();
@@ -199,6 +204,20 @@
mode->stateChanged( previous );
}
+ if ( previous == Constructed ) {
+ QAbstractItemModel* model = Application::instance().model().eventModel();
+ connect( model, SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& \
) ), + SLOT( slotUpdateTotal() ) );
+ connect( model, SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
+ SLOT( slotUpdateTotal() ) );
+ connect( model, SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
+ SLOT( slotUpdateTotal() ) );
+ connect( model, SIGNAL( layoutChanged() ),
+ SLOT( slotUpdateTotal() ) );
+ connect( model, SIGNAL( modelReset() ),
+ SLOT( slotUpdateTotal() ) );
+ }
+
switch( Application::instance().state() ) {
case Connected:
// FIXME remember in Gui state:
@@ -210,7 +229,6 @@
saveGuiState();
m_ui->viewStack->setCurrentWidget( m_ui->openingPage );
break;
- // fallthrough intended
case StartingUp:
m_ui->viewStack->setCurrentWidget( m_ui->openingPage );
restoreGuiState();
@@ -420,4 +438,28 @@
sendCommand( cmd );
}
+static int totalDuration( const EventIdList& eventList )
+{
+ int total = 0;
+ Q_FOREACH( EventId id, eventList ) {
+ const Event& event = DATAMODEL->eventForId( id );
+ total += event.duration();
+ }
+ return total;
+}
+
+void MainWindow::slotUpdateTotal()
+{
+ const QDate today = QDate::currentDate();
+ const EventIdList todayEvents = DATAMODEL->eventsThatStartInTimeFrame(
+ QDateTime( today ), QDateTime( today.addDays(1) ) );
+ m_statusBarLabelDayTotal.setText( tr("Day total: \
%1").arg(hoursAndMinutes(totalDuration(todayEvents))) ); +
+ const TimeSpan thisWeek( today.addDays( - today.dayOfWeek() + 1 ),
+ today.addDays( 7 - today.dayOfWeek() + 1 ) );
+ const EventIdList weekEvents = DATAMODEL->eventsThatStartInTimeFrame(
+ QDateTime( thisWeek.first ), QDateTime( thisWeek.second ) );
+ m_statusBarLabelWeekTotal.setText( tr("Week total: \
%1").arg(hoursAndMinutes(totalDuration(weekEvents))) ); +}
+
#include "MainWindow.moc"
--- trunk/playground/utils/charm/trunk/Charm/MainWindow.h #756533:756534
@@ -1,6 +1,7 @@
#ifndef CHARM_MAINWINDOW_H
#define CHARM_MAINWINDOW_H
+#include <QLabel>
#include <QMenu>
#include <QList>
#include <QAction>
@@ -50,8 +51,11 @@
void sendCommand( CharmCommand* );
void restore();
+
+private slots:
void slotAboutDialog();
void slotReportDialog();
+ void slotUpdateTotal();
protected:
void showEvent( QShowEvent* );
@@ -85,6 +89,8 @@
EventEditor m_eventEditor;
QAction m_actionReporting;
ReportDialog m_reportDialog;
+ QLabel m_statusBarLabelWeekTotal;
+ QLabel m_statusBarLabelDayTotal;
};
#endif
--- trunk/playground/utils/charm/trunk/Core/CharmConstants.h #756533:756534
@@ -34,7 +34,6 @@
extern const QString MetaKey_Key_24hEditing;
#define CONFIGURATION ( Configuration::instance() )
-#define DATAMODEL ( MODEL.charmDataModel() )
// two helper functions to persist meta data:
bool boolForString( const QString& );
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic