From 51744b9fe461a2a043f4640d62919b4819ca3bdb Mon Sep 17 00:00:00 2001 From: David Greaves Date: Sat, 25 Apr 2009 22:13:42 +0100 Subject: [PATCH] Move from SLabel to ActiveLabel Prepare to have expanding/contracting categories Abort move to (buggy) C++, not CSS shading Change colour scheme Move to grey Notes in bracks : NoteWidget --- shopper.pro | 4 ++ src/ui/ActiveLabel.cc | 45 ++++++++++++++++ src/ui/ActiveLabel.h | 42 +++++++++++++++ src/ui/CategoryView.cc | 41 ++++++++++++--- src/ui/CategoryView.h | 2 + src/ui/ItemView.cc | 36 ++++++------- src/ui/ItemView.h | 8 +-- src/ui/LabelEntry.cc | 29 ++--------- src/ui/LabelEntry.h | 16 +----- src/ui/ListView.cc | 1 + src/ui/NoteWidget.cc | 97 +++++++++++++++++++++++++++++++++++ src/ui/{LabelEntry.h => NoteWidget.h} | 45 +++++----------- 12 files changed, 266 insertions(+), 100 deletions(-) create mode 100644 src/ui/ActiveLabel.cc create mode 100644 src/ui/ActiveLabel.h create mode 100644 src/ui/NoteWidget.cc copy src/ui/{LabelEntry.h => NoteWidget.h} (52%) diff --git a/shopper.pro b/shopper.pro index 8f696e4..8d56137 100644 --- a/shopper.pro +++ b/shopper.pro @@ -22,6 +22,8 @@ HEADERS += src/CatListModel.h \ src/ui/ItemDialog.h \ src/ui/PreferencesDialog.h \ src/ui/LabelEntry.h \ + src/ui/ActiveLabel.h \ + src/ui/NoteWidget.h \ src/ui/mainwindow.h \ src/ui/notify.h \ src/ui/ItemView.h \ @@ -41,6 +43,8 @@ SOURCES += src/CatListModel.cc \ src/ui/ItemDialog.cc \ src/ui/PreferencesDialog.cc \ src/ui/LabelEntry.cc \ + src/ui/ActiveLabel.cc \ + src/ui/NoteWidget.cc \ src/ui/mainwindow.cc \ src/ui/notify.cc \ src/ui/ItemView.cc \ diff --git a/src/ui/ActiveLabel.cc b/src/ui/ActiveLabel.cc new file mode 100644 index 0000000..81fdf53 --- /dev/null +++ b/src/ui/ActiveLabel.cc @@ -0,0 +1,45 @@ +/* Shopper + * Copyright (C) 2008 David Greaves + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ +//#define DEBUG_SHOPPER 1 +#include "ActiveLabel.h" +#include "shopper.h" // automake, i8n, gettext +#include "GestureWatcher.h" + +namespace Shopper +{ + // ActiveLabel a label that emits pressed() when clicked + ActiveLabel::ActiveLabel(QWidget * parent, Qt::WindowFlags f ) : + QLabel(parent, f) + { + } + ActiveLabel::ActiveLabel( const QString & text, QWidget * parent, Qt::WindowFlags f ) : + QLabel(text, parent, f) + { + } + + void ActiveLabel::mouseReleaseEvent ( QMouseEvent * event ) + { + if (event->button() == Qt::LeftButton) { + event->accept(); + emit pressed(); + } + event->ignore(); + } +} diff --git a/src/ui/ActiveLabel.h b/src/ui/ActiveLabel.h new file mode 100644 index 0000000..01f2018 --- /dev/null +++ b/src/ui/ActiveLabel.h @@ -0,0 +1,42 @@ +/* Shopper + * Copyright (C) 2008 David Greaves + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ +#ifndef ACTIVELABEL_H +#define ACTIVELABEL_H + +#include "shopper.h" // automake, i8n, gettext +#include +#include + +namespace Shopper +{ + // ActiveLabel a label that emits pressed() when clicked + class ActiveLabel: public QLabel + { + Q_OBJECT; + public: + explicit ActiveLabel(QWidget * parent = 0, Qt::WindowFlags f = 0 ); + explicit ActiveLabel(const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0); + void mouseReleaseEvent ( QMouseEvent * event ); + signals: + void pressed(); + }; +} + +#endif // ACTIVELABEL_H diff --git a/src/ui/CategoryView.cc b/src/ui/CategoryView.cc index 1fc625d..4c36b91 100644 --- a/src/ui/CategoryView.cc +++ b/src/ui/CategoryView.cc @@ -44,9 +44,13 @@ namespace Shopper QHash itemMap; - SLabel *cvName; /* This displays the category description */ + QWidget *cvHead; /* This displays the category description */ + QImage *cvExpandImg; + QLabel *cvName; + QWidget *cvList; QVBoxLayout *cvBox; + int expanded; int zoom; }; @@ -59,21 +63,40 @@ namespace Shopper p->mycat = &cat; p->mylist = &l; p->zoom = 0; + + + QPalette pName = palette(); + pName.setColor(QPalette::WindowText, QColor(255,255,255)); +/* + QLinearGradient bgGrad = QLinearGradient(); + bgGrad.setCoordinateMode(QGradient::ObjectBoundingMode); + bgGrad.setColorAt(0.0, QColor(132,143,150)); + bgGrad.setColorAt(0.5, QColor(85,104,121)); + bgGrad.setColorAt(0.50, QColor(16,50,71)); + bgGrad.setColorAt(1.0, QColor(176,191,201)); + pName.setBrush(QPalette::Window, bgGrad); +*/ + QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); sizePolicy.setHorizontalStretch(1); sizePolicy.setVerticalStretch(0); setSizePolicy(sizePolicy); // setFrameStyle(QFrame::Panel|QFrame::Sunken); - p->cvName = new SLabel(p->mycat->get_name(), this); - p->cvName->setAlignment(Qt::AlignCenter); - p->cvName->setSizePolicy(sizePolicy); - p->cvName->setStyleSheet("background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 white, stop: 0.4 rgb(100,100,255), stop:1 white)"); - + p->cvName = new QLabel(p->mycat->get_name(),this); // Lay them out p->cvBox = new QVBoxLayout(); p->cvBox->addWidget(p->cvName); p->cvBox->setContentsMargins(0, 0, 0, 0); + p->cvName->setStyleSheet("background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(132,143,150), stop: 0.5 rgb(85,104,121), stop: 0.5001 rgb(16,50,71), stop:1.0 rgb(176,191,201) )"); + + p->cvName->setAlignment(Qt::AlignLeft); + p->cvName->setSizePolicy(sizePolicy); + + p->cvName->setAutoFillBackground(true); + p->cvName->setPalette(pName); + + // Add the items setup(); @@ -116,6 +139,12 @@ namespace Shopper p->itemMap.remove(i); } + void CategoryView::minimise() + { + } + void CategoryView::maximise() + { + } void CategoryView::setup() { ItemView *iv; diff --git a/src/ui/CategoryView.h b/src/ui/CategoryView.h index c81f82f..5250461 100644 --- a/src/ui/CategoryView.h +++ b/src/ui/CategoryView.h @@ -44,6 +44,8 @@ namespace Shopper void add_item(Item*); void del_item(Item*); void setZoom(int); + void minimise(); + void maximise(); private: void setup(); diff --git a/src/ui/ItemView.cc b/src/ui/ItemView.cc index d4fd482..611f216 100644 --- a/src/ui/ItemView.cc +++ b/src/ui/ItemView.cc @@ -22,6 +22,7 @@ #include "shopper.h" // automake, i8n, gettext #include "ItemDialog.h" #include "LabelEntry.h" +#include "NoteWidget.h" #include #include #include @@ -53,11 +54,11 @@ namespace Shopper // setStyleSheet("color : green;margin: 0px;border: 0px ;padding: 0px ;"); // setMargin(0); QPalette p = palette(); - p.setColor(QPalette::WindowText, QColor(0,100,0)); + p.setColor(QPalette::WindowText, QColor(0,0,0)); setPalette(p); - QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); - sizePolicy.setHorizontalStretch(1); + QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); + sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); setSizePolicy(sizePolicy); @@ -65,10 +66,9 @@ namespace Shopper tick = new QCheckBox(this); // The tick represents either wanted or bought tick->setChecked(active); - desc = new SLabel(myitem->get_desc(), this); + desc = new ActiveLabel(myitem->get_desc(), this); desc->setAlignment(Qt::AlignLeft); desc->setSizePolicy(sizePolicy); - desc->setPalette(p); desc->setMargin(0); QFont font = desc->font(); if (mylist->get_state() == MAKING_LIST) @@ -80,20 +80,21 @@ namespace Shopper // Lay them out outer_b.addWidget(tick); outer_b.addLayout(&inner_b,1); - inner_b.addWidget(desc, 1); + inner_b.addWidget(desc, 0); // maybe show a note if (! showTwoColumns) { - note = new LabelEntry(myitem->get_note(),this); + note = new NoteWidget(myitem->get_note(),this); note->setAlignment(Qt::AlignLeft); note->setSizePolicy(sizePolicy); + p.setColor(QPalette::WindowText, QColor(150,150,150)); + note->setPalette(p); // note->setStyleSheet("border: 1px solid gray"); - note->label()->setMargin(0); - note->label()->setLineWidth(2); - note->label()->setMidLineWidth(1); - note->label()->setFrameStyle(QFrame::Panel | QFrame::Sunken); - note->label()->setPalette(p); - +// note->label()->setMargin(0); +// note->label()->setLineWidth(2); +// note->label()->setMidLineWidth(1); +// note->label()->setFrameStyle(QFrame::Panel | QFrame::Sunken); + inner_b.addWidget(note, 1); // Respond to clicking the note connect(note, SIGNAL(changed()), @@ -111,9 +112,9 @@ namespace Shopper // We gesture over the description to activate it GestureWatcher* gw = GestureWatcher::getGestureWatcher(); - gw->connect(desc, Gesture("r l "), + gw->connect(desc, Gesture("l "), this, SLOT(desc_clicked())); - gw->connect(desc, Gesture("l r "), + gw->connect(desc, Gesture("r "), this, SLOT(desc_clicked())); // And clicking the description is the same. @@ -162,9 +163,8 @@ namespace Shopper void ItemView::note_changed() { - myitem->set_note(note->getText()); // Setting the data - // will call an - // update on the note + myitem->set_note(note->text()); // Setting the data will call + // an update on the note } void ItemView::edit_item() { diff --git a/src/ui/ItemView.h b/src/ui/ItemView.h index ef6fa24..d93c3bf 100644 --- a/src/ui/ItemView.h +++ b/src/ui/ItemView.h @@ -29,8 +29,8 @@ namespace Shopper { class Item; class List; - class SLabel; - class LabelEntry; + class ActiveLabel; + class NoteWidget; class ItemView: public QWidget { Q_OBJECT; @@ -47,8 +47,8 @@ namespace Shopper */ QHBoxLayout outer_b; QHBoxLayout inner_b; - SLabel *desc; /* This displays the item description */ - LabelEntry *note; /* This displays the notes. When + ActiveLabel *desc; /* This displays the item description */ + NoteWidget *note; /* This displays the notes. When * clicked on it transforms into a * textEntry */ Item *myitem; /* the item being displayed */ diff --git a/src/ui/LabelEntry.cc b/src/ui/LabelEntry.cc index e4106e4..87f2c7b 100644 --- a/src/ui/LabelEntry.cc +++ b/src/ui/LabelEntry.cc @@ -19,6 +19,7 @@ */ //#define DEBUG_SHOPPER 1 #include "LabelEntry.h" +#include "ActiveLabel.h" #include "shopper.h" // automake, i8n, gettext #include "GestureWatcher.h" #include @@ -31,28 +32,6 @@ namespace Shopper { - // SLabel a label that emits pressed() when clicked - SLabel::SLabel(QWidget * parent, Qt::WindowFlags f ) : - QLabel(parent, f) - { - } - SLabel::SLabel( const QString & text, QWidget * parent, Qt::WindowFlags f ) : - QLabel(text, parent, f) - { - } - void SLabel::setVisible(bool vis) - { - QLabel::setVisible(vis); - } - void SLabel::mouseReleaseEvent ( QMouseEvent * event ) - { - if (event->button() == Qt::LeftButton) { - event->accept(); - emit pressed(); - } - event->ignore(); - } - // LabelEntry - a label that turns into a textbox when clicked LabelEntry::LabelEntry(QWidget *parent) : QWidget(parent), @@ -72,11 +51,11 @@ namespace Shopper } void LabelEntry::init() { - myLabel = new SLabel(data, this); + myLabel = new ActiveLabel(data, this); GestureWatcher* gw = GestureWatcher::getGestureWatcher(); - gw->connect(myLabel, Gesture("r l "), + gw->connect(myLabel, Gesture("l "), this, SLOT(label_clicked())); - gw->connect(myLabel, Gesture("l r "), + gw->connect(myLabel, Gesture("r "), this, SLOT(label_clicked())); // connect(myLabel, SIGNAL(pressed()), // this, SLOT(label_clicked())); diff --git a/src/ui/LabelEntry.h b/src/ui/LabelEntry.h index d654957..cc45574 100644 --- a/src/ui/LabelEntry.h +++ b/src/ui/LabelEntry.h @@ -21,6 +21,7 @@ #define LABELENTRY_H #include "shopper.h" // automake, i8n, gettext +#include "ActiveLabel.h" #include #include #include @@ -29,19 +30,6 @@ namespace Shopper { - // SLabel a label that emits pressed() when clicked - class SLabel: public QLabel - { - Q_OBJECT; - public: - explicit SLabel(QWidget * parent = 0, Qt::WindowFlags f = 0 ); - explicit SLabel(const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0); - void mouseReleaseEvent ( QMouseEvent * event ); - virtual void setVisible(bool vis); - signals: - void pressed(); - }; - // LabelEntry - a label that turns into a textbox when clicked class LabelEntry : public QWidget { @@ -64,7 +52,7 @@ namespace Shopper protected: QString data; - SLabel *myLabel; + ActiveLabel *myLabel; QLineEdit *entry; QHBoxLayout layout; diff --git a/src/ui/ListView.cc b/src/ui/ListView.cc index 97e713e..706bf9e 100644 --- a/src/ui/ListView.cc +++ b/src/ui/ListView.cc @@ -63,6 +63,7 @@ namespace Shopper p->lvBox = 0; QSettings settings; p->zoom = settings.value("ui/ZoomLevel", 4).toInt(); + viewport()->setAutoFillBackground(false); // setBackgroundRole(QPalette::Light); setWidgetResizable(true); diff --git a/src/ui/NoteWidget.cc b/src/ui/NoteWidget.cc new file mode 100644 index 0000000..f3c385c --- /dev/null +++ b/src/ui/NoteWidget.cc @@ -0,0 +1,97 @@ +/* Shopper + * Copyright (C) 2008 David Greaves + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ +//#define DEBUG_SHOPPER 1 +#include "NoteWidget.h" +#include "shopper.h" // automake, i8n, gettext +#include "GestureWatcher.h" +#include +#include +#include +#include +#include +#include +#include + +namespace Shopper +{ + // NoteWidget - Shopper note widget + NoteWidget::NoteWidget(QWidget *parent) : + QLabel(parent), + data(""), + entry(0) + { + init(); + } + NoteWidget::NoteWidget(const QString & value, QWidget *parent) : + QLabel(parent), + data(value), + entry(0) + { + init(); + } + void NoteWidget::init() + { + GestureWatcher* gw = GestureWatcher::getGestureWatcher(); + gw->connect(this, Gesture("l "), + this, SLOT(labelClicked())); + gw->connect(this, Gesture("r "), + this, SLOT(labelClicked())); + } + + QString NoteWidget::text() + { + return data; + } + void NoteWidget::setText ( const QString & d ) + { + data = d; + QLabel::setText(data.isEmpty() ? "" : "("+data+")"); // display () if there is a note. + } + void NoteWidget::labelClicked() + { + _ENTER; + if (entry != 0) return; // events may arrive post-creation + QLabel::setText(""); + entry = new QLineEdit(this); + entry->setSizePolicy(sizePolicy()); + entry->setText(data); + entry->setFont(QLabel::font()); + // self-destruct on unfocus or activate + connect(entry, SIGNAL(editingFinished()), + this, SLOT(entryFinished())); + entry->show(); + entry->setFocus(Qt::MouseFocusReason); + } + void NoteWidget::entryFinished() + { + if (entry == 0) return; // events may arrive post-deletion + data=entry->text(); + QLabel::setText(data.isEmpty() ? "" : "("+data+")"); + entry->hide(); + entry->deleteLater(); // We can now forget about it... + entry=0; + emit changed(); + } + void NoteWidget::setFont ( const QFont & f) + { + QLabel::setFont(f); + if (entry) entry->setFont(f); + } +} diff --git a/src/ui/LabelEntry.h b/src/ui/NoteWidget.h similarity index 52% copy from src/ui/LabelEntry.h copy to src/ui/NoteWidget.h index d654957..900ac74 100644 --- a/src/ui/LabelEntry.h +++ b/src/ui/NoteWidget.h @@ -17,8 +17,8 @@ * 02110-1301 USA * */ -#ifndef LABELENTRY_H -#define LABELENTRY_H +#ifndef NOTEWIDGET_H +#define NOTEWIDGET_H #include "shopper.h" // automake, i8n, gettext #include @@ -29,50 +29,29 @@ namespace Shopper { - // SLabel a label that emits pressed() when clicked - class SLabel: public QLabel +// NoteWidget - represent a shopper Note + class NoteWidget : public QLabel { Q_OBJECT; public: - explicit SLabel(QWidget * parent = 0, Qt::WindowFlags f = 0 ); - explicit SLabel(const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0); - void mouseReleaseEvent ( QMouseEvent * event ); - virtual void setVisible(bool vis); - signals: - void pressed(); - }; - -// LabelEntry - a label that turns into a textbox when clicked - class LabelEntry : public QWidget - { - Q_OBJECT; - public: - LabelEntry(QWidget *parent = 0); - explicit LabelEntry(const QString & label, QWidget *parent = 0); + NoteWidget(QWidget *parent = 0); + explicit NoteWidget(const QString & note, QWidget *parent = 0); private: void init(); // real constructor public: - QString getText(); - void setAlignment ( Qt::Alignment al ); - void setText ( const QString & d); - virtual void setVisible(bool vis); - void setFrameStyle(int i); - void setSizePolicy(QSizePolicy::Policy h, QSizePolicy::Policy v); - void setSizePolicy(QSizePolicy p); - void setFont ( const QFont & ); - QLabel* label(); + QString text(); + void setText( const QString & d); + void setFont( const QFont & f); protected: QString data; - SLabel *myLabel; QLineEdit *entry; - QHBoxLayout layout; public slots: - void label_clicked(); - void entry_finished(); + void labelClicked(); + void entryFinished(); signals: void changed(); }; } -#endif // LABELENTRY_H +#endif // NOTEWIDGET_H -- 2.11.4.GIT