From: konrad Date: Wed, 5 Mar 2008 13:25:01 +0000 (+0000) Subject: add check dialog X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=a472ef65fdcc2af7968f9fa007a01594446a45be;p=web%2Fkonrad%2Fsmoke.git add check dialog git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@104 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/checkdlg.cpp b/src/checkdlg.cpp new file mode 100644 index 0000000..6362073 --- /dev/null +++ b/src/checkdlg.cpp @@ -0,0 +1,104 @@ +// +// C++ Implementation: checkdlg +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "checkdlg.h" + +#include +#include +#include +#include + +MCheckDialog::MCheckDialog(QWidget*parent,const MCheckList&checks,QString title) + :QDialog(parent),m_list(checks) +{ + setWindowTitle(title); + //basic layout + QVBoxLayout *vl=new QVBoxLayout; + setLayout(vl); + QScrollArea *sa=new QScrollArea; + vl->addWidget(sa,10); + QHBoxLayout *hl=new QHBoxLayout; + vl->addLayout(hl,0); + hl->addStretch(10); + QPushButton*p; + hl->addWidget(p=new QPushButton(tr("Ok")),0); + connect(p,SIGNAL(clicked()),this,SLOT(accept())); + hl->addWidget(p=new QPushButton(tr("Cancel")),0); + connect(p,SIGNAL(clicked()),this,SLOT(reject())); + //fill area + QWidget*w=new QWidget; + w->setLayout(vl=new QVBoxLayout); + for(int i=0;isetChecked(m_list[i].isSet()); + vl->addWidget(cb); + m_boxes.append(cb); + } + sa->setWidget(w); +} + +MCheckList MCheckDialog::getCheckList()const +{ + for(int i=0;iisChecked()); + return m_list; +} + +/**************************************************/ + +MCheckItem::MCheckItem(){} +MCheckItem::~MCheckItem(){} + +QString MCheckItem::key()const{return label();} + +MCheckList::MCheckList(){} + +MCheckList::MCheckList(const MCheckList&l) +{ + for(int i=0;icopy()); +} + +MCheckList& MCheckList::operator=(const MCheckList&l) +{ + for(int i=0;icopy()); +} + +MCheckList::~MCheckList() +{ + for(int i=0;i, (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_CHECKDLG_H +#define MAGICSMOKE_CHECKDLG_H + +#include +#include + +class QCheckBox; + +/**abstract base class for items that can be displayed in a MCheckDialog*/ +class MCheckItem +{ + public: + /**constructs an empty check item*/ + MCheckItem(); + /**deletes the check item*/ + virtual ~MCheckItem(); + + /**overwrite this to return a label that can be displayed*/ + virtual QString label()const=0; + /**overwrite this to return a key string that identifies the item (default implementation returns the label)*/ + virtual QString key()const; + /**overwrite this to return whether the item is checked*/ + virtual bool isSet()const=0; + /**overwrite this to change the checking status of the item*/ + virtual void set(bool)=0; + + protected: + friend class MCheckList; + /**overwrite this to creat an exact copy of the item (must be implemented and must return non-NULL)*/ + virtual MCheckItem* copy()const=0; +}; + +/**implements a list of checkable items*/ +class MCheckList +{ + public: + /**instantiate an empty list*/ + MCheckList(); + /**creates an exact copy of the list (uses MCheckItem::copy() )*/ + MCheckList(const MCheckList&); + /**deletes the list*/ + ~MCheckList(); + + /**adds an item to the list*/ + void addItem(MCheckItem*); + /**returns the size of the list*/ + int size()const; + + /**returns a writable reference to an item*/ + MCheckItem& operator[](int); + /**returns a const reference to an item*/ + const MCheckItem& operator[](int)const; + + /**makes this list an exact copy of the argument*/ + MCheckList& operator=(const MCheckList&); + private: + QList m_items; +}; + +/**a dialog that consists of check boxes in a QScrollArea */ +class MCheckDialog:public QDialog +{ + Q_OBJECT + public: + /**creates the dialog*/ + MCheckDialog(QWidget*parent,const MCheckList&checks,QString title); + + /**returns the current state of all check boxes, the return value is an exact copy of the check list from the constructor with updated check settings*/ + MCheckList getCheckList()const; + private: + QListm_boxes; + mutable MCheckList m_list; +}; + +#endif