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);
}
}
-void MEventEditor::setFlags()
-{
- flags->setText(MFlagEditor::edit(this, flags->text(), tr("Edit flags of event %1:").arg(event.title())));
-}
-
-
void MEventEditor::updatePrice()
{
pricemodel->clear();
#include "MOEvent"
+class MFlagWidget;
class QCheckBox;
class QDateTime;
class QDateTimeEdit;
/**removes a price*/
void removePrice();
- ///change flags
- void setFlags();
private:
MOEvent event;
QDateTimeEdit*starttime,*endtime;
QTextEdit*description,*comment;
QCheckBox*cancelcheck;
QSpinBox*capacity;
- QLabel*eventid,*flags;
+ QLabel*eventid;
+ MFlagWidget*flags;
QTableView*pricetable;
QStandardItemModel*pricemodel;
};
#include <QBoxLayout>
#include <QComboBox>
#include <QCoreApplication>
+#include <QDebug>
#include <QGridLayout>
#include <QHeaderView>
#include <QItemDelegate>
#include <QLabel>
+#include <QLineEdit>
#include <QPushButton>
#include <QStandardItemModel>
#include <QTableView>
+#include <QToolButton>
static const int MIGNORE=0;
static const int MMUST=1;
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!"<<hex<<(quint64)this;
+ return;
+ }
+ if(e){
+ if(m_btn==0){
+ hl->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());
+}
#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
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