[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [skrooge/Feature] plugins/skrooge/skrooge_budget: feature: Progress bar in budget table
From: Stephane Mankowski <stephane () mankowski ! fr>
Date: 2012-04-30 20:46:22
Message-ID: 20120430204622.77538A60A9 () git ! kde ! org
[Download RAW message or body]
Git commit 4c068fc85f6ae54439f2b6a8d76d8063e6b634af by Stephane Mankowski.
Committed on 30/04/2012 at 22:45.
Pushed by smankowski into branch 'Feature'.
feature: Progress bar in budget table
M +1 -0 plugins/skrooge/skrooge_budget/CMakeLists.txt
A +152 -0 plugins/skrooge/skrooge_budget/skgbudgetdelegate.cpp [License: GPL \
(v2+)] A +58 -0 plugins/skrooge/skrooge_budget/skgbudgetdelegate.h \
[License: GPL (v2+)] M +3 -0 \
plugins/skrooge/skrooge_budget/skgbudgetpluginwidget.cpp
http://commits.kde.org/skrooge/4c068fc85f6ae54439f2b6a8d76d8063e6b634af
diff --git a/plugins/skrooge/skrooge_budget/CMakeLists.txt \
b/plugins/skrooge/skrooge_budget/CMakeLists.txt index 549c5aa..013a679 100644
--- a/plugins/skrooge/skrooge_budget/CMakeLists.txt
+++ b/plugins/skrooge/skrooge_budget/CMakeLists.txt
@@ -11,6 +11,7 @@ ${CMAKE_BINARY_DIR}/skgbasegui
LINK_DIRECTORIES (${LIBRARY_OUTPUT_PATH})
SET(skrooge_budget_SRCS
+ skgbudgetdelegate.cpp
skgbudgetplugin.cpp
skgbudgetpluginwidget.cpp)
diff --git a/plugins/skrooge/skrooge_budget/skgbudgetdelegate.cpp \
b/plugins/skrooge/skrooge_budget/skgbudgetdelegate.cpp new file mode 100644
index 0000000..6fa3db7
--- /dev/null
+++ b/plugins/skrooge/skrooge_budget/skgbudgetdelegate.cpp
@@ -0,0 +1,152 @@
+/***************************************************************************
+ * Copyright (C) 2008 by S. MANKOWSKI / G. DE BURE support@mankowski.fr *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see <http://www.gnu.org/licenses/> *
+ ***************************************************************************/
+/** @file
+ * This file is a delegate for budget.
+ *
+ * @author Stephane MANKOWSKI / Guillaume DE BURE
+ */
+#include "skgbudgetdelegate.h"
+#include "skgobjectmodelbase.h"
+#include "skgtraces.h"
+#include "skgprogressbar.h"
+
+#include <kcolorscheme.h>
+
+#include <QSortFilterProxyModel>
+#include <QPainter>
+
+SKGBudgetDelegate::SKGBudgetDelegate(QObject* parent, SKGDocument* iDoc) : \
QStyledItemDelegate(parent), m_document(iDoc) +{}
+
+SKGBudgetDelegate::~SKGBudgetDelegate()
+{
+ m_document = NULL;
+}
+
+void SKGBudgetDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, \
const QModelIndex& index) const +{
+ if (!index.isValid()) return;
+ SKGObjectModelBase* m = qobject_cast<SKGObjectModelBase*> ((QAbstractItemModel*) \
index.model()); + QSortFilterProxyModel* p = qobject_cast<QSortFilterProxyModel*> \
((QAbstractItemModel*) index.model()); + if (p) m = (SKGObjectModelBase*) \
p->sourceModel(); + if (m) {
+ QString att = m->getAttribute(index.column());
+ if (att == "f_budgeted" || att == "f_budgeted_modified") {
+ QModelIndex idxs = (p ? p->mapToSource(index) : index);
+ SKGObjectBase obj = m->getObject(idxs);
+
+ double budgeted = SKGServices::stringToDouble(obj.getAttribute(att));
+ double amount = \
SKGServices::stringToDouble(obj.getAttribute("f_CURRENTAMOUNT")); +
+
+ painter->save();
+ painter->setRenderHint(QPainter::Antialiasing);
+
+ KColorScheme scheme(QPalette::Normal);
+ QColor negative = scheme.foreground(KColorScheme::NegativeText).color();
+ QColor positive = scheme.foreground(KColorScheme::PositiveText).color();
+ QColor back = scheme.foreground(KColorScheme::LinkText).color();
+
+ QStyleOptionViewItemV4 opt = option;
+ QStyledItemDelegate::initStyleOption(&opt, index);
+ QRect rect = opt.rect.adjusted(1, 1, -1, -1);
+
+ painter->setPen(Qt::NoPen);
+
+ if (budgeted >= 0) {
+ if (amount < 0) amount = 0;
+ //Income
+ if (amount < budgeted) {
+ //Zone rouge
+ {
+ QBrush selectionBrush(negative);
+ painter->setBrush(selectionBrush);
+ painter->drawRect(rect);
+ }
+
+ //Zone bleu
+ {
+ QBrush selectionBrush(back);
+ painter->setBrush(selectionBrush);
+ QRect r2(rect.left(), rect.top(), rect.width()*amount / \
budgeted, rect.height()); + painter->drawRect(r2);
+ }
+ } else {
+ //Zone verte
+ {
+ QBrush selectionBrush(positive);
+ painter->setBrush(selectionBrush);
+ painter->drawRect(rect);
+ }
+
+ //Zone bleu
+ {
+ QBrush selectionBrush(back);
+ painter->setBrush(selectionBrush);
+ QRect r2(rect.left(), rect.top(), rect.width()*budgeted / \
amount, rect.height()); + painter->drawRect(r2);
+ }
+ }
+ } else {
+ if (amount > 0) amount = 0;
+ //Expenditure
+ if (amount < budgeted) {
+ //Zone rouge
+ {
+ QBrush selectionBrush(negative);
+ painter->setBrush(selectionBrush);
+ painter->drawRect(rect);
+ }
+
+ //Zone bleu
+ {
+ QBrush selectionBrush(back);
+ painter->setBrush(selectionBrush);
+ QRect r2(rect.left(), rect.top(), rect.width()*budgeted / \
amount, rect.height()); + painter->drawRect(r2);
+ }
+ } else {
+ //Zone verte
+ {
+ QBrush selectionBrush(positive);
+ painter->setBrush(selectionBrush);
+ painter->drawRect(rect);
+ }
+
+ //Zone bleu
+ {
+ QBrush selectionBrush(back);
+ painter->setBrush(selectionBrush);
+ QRect r2(rect.left(), rect.top(), rect.width()*amount / \
budgeted, rect.height()); + painter->drawRect(r2);
+ }
+ }
+ }
+
+ painter->setPen(Qt::white);
+ QTextOption to;
+ to.setAlignment(Qt::AlignCenter);
+ painter->drawText(rect, m->data(idxs).toString(), to);
+
+ painter->restore();
+ return;
+ }
+ }
+ QStyledItemDelegate::paint(painter, option, index);
+}
+
+#include "skgbudgetdelegate.moc"
diff --git a/plugins/skrooge/skrooge_budget/skgbudgetdelegate.h \
b/plugins/skrooge/skrooge_budget/skgbudgetdelegate.h new file mode 100644
index 0000000..7660fc0
--- /dev/null
+++ b/plugins/skrooge/skrooge_budget/skgbudgetdelegate.h
@@ -0,0 +1,58 @@
+/***************************************************************************
+ * Copyright (C) 2008 by S. MANKOWSKI / G. DE BURE support@mankowski.fr *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see <http://www.gnu.org/licenses/> *
+ ***************************************************************************/
+#ifndef SKGBUDGETDELEGATE_H
+#define SKGBUDGETDELEGATE_H
+/** @file
+* This file is a delegate for budget.
+*
+* @author Stephane MANKOWSKI / Guillaume DE BURE
+*/
+#include <QStyledItemDelegate>
+
+class SKGDocument;
+
+/**
+ * This file is a delegate for budget
+ */
+class SKGBudgetDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ /**
+ * Default Constructor
+ */
+ explicit SKGBudgetDelegate(QObject* parent = 0, SKGDocument* iDoc = NULL);
+
+ /**
+ * Default Destructor
+ */
+ virtual ~SKGBudgetDelegate();
+
+
+ virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const \
QModelIndex& index) const; +
+
+private:
+ Q_DISABLE_COPY(SKGBudgetDelegate);
+
+ SKGDocument* m_document;
+ QString m_negativeStyleSheet;
+ QString m_neutralStyleSheet;
+ QString m_positiveStyleSheet;
+};
+
+#endif // SKGBUDGETDELEGATE_H
diff --git a/plugins/skrooge/skrooge_budget/skgbudgetpluginwidget.cpp \
b/plugins/skrooge/skrooge_budget/skgbudgetpluginwidget.cpp index 8d422d6..0e30594 \
100644
--- a/plugins/skrooge/skrooge_budget/skgbudgetpluginwidget.cpp
+++ b/plugins/skrooge/skrooge_budget/skgbudgetpluginwidget.cpp
@@ -20,6 +20,7 @@
* @author Stephane MANKOWSKI
*/
#include "skgbudgetpluginwidget.h"
+#include "skgbudgetdelegate.h"
#include "skgmainpanel.h"
#include "skgobjectmodel.h"
#include "skgbudgetobject.h"
@@ -123,6 +124,8 @@ SKGBudgetPluginWidget::SKGBudgetPluginWidget(SKGDocument* \
iDocument)
ui.kModeCmb->addItem(i18nc("Noun, mode item to a apply a transfer of budget", \
"Current"), SKGBudgetRuleObject::CURRENT);
ui.kModeCmb->addItem(i18nc("Noun, mode item to a apply a transfer of budget", \
"Current year"), SKGBudgetRuleObject::YEAR);
+ ui.kView->getView()->setItemDelegate(new SKGBudgetDelegate(ui.kView->getView(), \
getDocument())); +
SKGDocumentBank* doc = static_cast<SKGDocumentBank*>(getDocument());
if (doc) {
ui.kUnitCmb->addItem("%");
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic