From 9967a4e6424720090e6b9ef332d27c9d35f69d24 Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Fri, 30 Dec 2011 14:10:17 +0100 Subject: [PATCH] make flags widget its own class --- src/dialogs/eventedit.cpp | 13 +------ src/dialogs/eventedit.h | 6 ++-- src/dialogs/flagedit.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++ src/dialogs/flagedit.h | 50 ++++++++++++++++++++++++++ 4 files changed, 142 insertions(+), 14 deletions(-) diff --git a/src/dialogs/eventedit.cpp b/src/dialogs/eventedit.cpp index f8c22a1..0163995 100644 --- a/src/dialogs/eventedit.cpp +++ b/src/dialogs/eventedit.cpp @@ -134,11 +134,8 @@ MEventEditor::MEventEditor(QWidget*pw,qint64 id) gl->addWidget(lab=new QLabel(tr("Flags:")),++lctr,0); lab->setAlignment(Qt::AlignRight|Qt::AlignVCenter); - gl->addLayout(hl=new QHBoxLayout,lctr,1); - hl->addWidget(flags=new QLabel(event.flags()),1); - flags->setFrameStyle(QFrame::StyledPanel|QFrame::Sunken); - hl->addWidget(p=new QPushButton("..."),0); - connect(p,SIGNAL(clicked(bool)),this,SLOT(setFlags())); + gl->addWidget(flags=new MFlagWidget(event.flags()),lctr,1); + flags->setEditorLabel(tr("Edit Flags of Event '%1'").arg(event.title())); tab->addTab(w=new QWidget,tr("Description")); w->setLayout(vl2=new QVBoxLayout); @@ -205,12 +202,6 @@ void MEventEditor::writeBack() } } -void MEventEditor::setFlags() -{ - flags->setText(MFlagEditor::edit(this, flags->text(), tr("Edit flags of event %1:").arg(event.title()))); -} - - void MEventEditor::updatePrice() { pricemodel->clear(); diff --git a/src/dialogs/eventedit.h b/src/dialogs/eventedit.h index d5b647b..61e449b 100644 --- a/src/dialogs/eventedit.h +++ b/src/dialogs/eventedit.h @@ -17,6 +17,7 @@ #include "MOEvent" +class MFlagWidget; class QCheckBox; class QDateTime; class QDateTimeEdit; @@ -62,8 +63,6 @@ class MEventEditor:public QDialog /**removes a price*/ void removePrice(); - ///change flags - void setFlags(); private: MOEvent event; QDateTimeEdit*starttime,*endtime; @@ -71,7 +70,8 @@ class MEventEditor:public QDialog QTextEdit*description,*comment; QCheckBox*cancelcheck; QSpinBox*capacity; - QLabel*eventid,*flags; + QLabel*eventid; + MFlagWidget*flags; QTableView*pricetable; QStandardItemModel*pricemodel; }; diff --git a/src/dialogs/flagedit.cpp b/src/dialogs/flagedit.cpp index b86e7af..16f1853 100644 --- a/src/dialogs/flagedit.cpp +++ b/src/dialogs/flagedit.cpp @@ -16,13 +16,16 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include +#include static const int MIGNORE=0; static const int MMUST=1; @@ -159,4 +162,88 @@ void MFlagEditor::reset() table->resizeColumnsToContents(); } +//++++++++++++++++++++++++++++++++++++++++++++++++++++ +MFlagWidget::MFlagWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) +{ + init(); +} + +MFlagWidget::MFlagWidget(QString flags, QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) +{ + init(); + setFlags(flags); +} + +MFlagWidget::MFlagWidget(QStringList flags, QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) +{ + init(); + setFlags(flags); +} + +void MFlagWidget::init() +{ + QHBoxLayout*hl; + setLayout(hl=new QHBoxLayout); + hl->addWidget(m_line=new QLabel(" "),1); + m_line->setFrameStyle(QFrame::StyledPanel|QFrame::Sunken); + m_btn=0; + setEditable(true); +} + +void MFlagWidget::setEditable(bool e) +{ + QHBoxLayout*hl=qobject_cast< QHBoxLayout* >(layout()); + if(hl==0){ + qDebug()<<"oops! MFlagWidget::setEditable has no layout!"<addWidget(m_btn=new QToolButton,0); + m_btn->setText("..."); + connect(m_btn,SIGNAL(clicked()),this,SLOT(doedit())); + } + }else{ + if(m_btn){ + m_btn->deleteLater(); + m_btn=0; + } + } +} + +void MFlagWidget::setReadonly(bool ro) +{ + setEditable(!ro); +} + +void MFlagWidget::setFlags(QString f) +{ + m_flags=f; + m_line->setText(f); +} + +void MFlagWidget::setFlags(QStringList fl) +{ + QString ff; + foreach(QString f,fl){ + if(!ff.isEmpty())ff+=" "; + ff+=f; + } + setFlags(ff); +} + +void MFlagWidget::setText(QString f) +{ + setFlags(f); +} + +void MFlagWidget::setEditorLabel(QString e) +{m_label=e;} + +void MFlagWidget::doedit() +{ + MFlagEditor mf(this,m_flags,m_label); + if(mf.exec()==QDialog::Accepted) + setFlags(mf.currentFlags()); +} diff --git a/src/dialogs/flagedit.h b/src/dialogs/flagedit.h index 17afb14..5b92368 100644 --- a/src/dialogs/flagedit.h +++ b/src/dialogs/flagedit.h @@ -18,8 +18,11 @@ #include "MOFlag" +class QLabel; class QStandardItemModel; class QTableView; +class QLineEdit; +class QAbstractButton; /**enables the user to edit flags attached to an entity as defined by MagicSmoke*/ class MFlagEditor:public QDialog @@ -48,4 +51,51 @@ class MFlagEditor:public QDialog void reset(); }; +///simple widget that displays flags and allows to edit them +class MFlagWidget:public QWidget +{ + Q_OBJECT + public: + ///creates a flag widget with no flags set, per default it is editable + MFlagWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); + ///creates a flag widget with flags set, per default it is editable + MFlagWidget(QString flags,QWidget* parent = 0, Qt::WindowFlags f = 0); + ///creates a flag widget with flags set, per default it is editable + MFlagWidget(QStringList flags,QWidget* parent = 0, Qt::WindowFlags f = 0); + + ///returns the currently displayed flags as string + QString flags()const{return m_flags;} + ///alias for flags() (for compatibility with other widgets) + QString text()const{return m_flags;} + + ///returns the label that will be used for the flag editor + QString editorLabel()const{return m_label;} + public slots: + ///sets the flags displayed in this widget + void setFlags(QString); + ///sets the flags displayed in this widget + void setFlags(QStringList); + ///sets the flags displayed in this widget (alias for compatibility with other widgets) + void setText(QString); + + ///sets the label for the flag editor when the user changes flags + void setEditorLabel(QString e); + + ///makes the widget editable (this is the default) + void setEditable(bool e=true); + ///makes the widget readonly (per default it is editable) + void setReadonly(bool ro=true); + + private slots: + /// \internal call the editor + void doedit(); + private: + QString m_flags,m_label; + QLabel*m_line; + QAbstractButton*m_btn; + + /// \internal helper for the constructors + void init(); +}; + #endif -- 1.7.2.5