#include "flagedit.h"
#include "misc.h"
-MEventEditor::MEventEditor(QWidget*pw,qint64 id)
+MEventEditor::MEventEditor(QWidget*pw, OpenMode mode, qint64 id)
:QDialog(pw)
{
- MTGetEvent ge=MTGetEvent::query(id);
- if(ge.stage()!=ge.Success){
- QMessageBox::warning(this,tr("Warning"),tr("Unable to load event from server."));
- //make myself disappear immediately
- QTimer::singleShot(1,this,SLOT(reject()));
- //no point in setting up widgets
- return;
+ if(id>=0){
+ MTGetEvent ge=MTGetEvent::query(id);
+ if(ge.stage()!=ge.Success){
+ QMessageBox::warning(this,tr("Warning"),tr("Unable to load event from server."));
+ //make myself disappear immediately
+ QTimer::singleShot(1,this,SLOT(reject()));
+ //no point in setting up widgets
+ return;
+ }
+ event=ge.getevent().value();
}
- event=ge.getevent().value();
+ switch(mode){
+ case OpenMode::Auto:
+ if(id>=0)break;
+ //else fallthru
+ case OpenMode::Create:
+ event.setid(Nullable<qint64>());
+ break;
+ default:break;
+ }
+
setWindowTitle(tr("Event Editor"));
QGridLayout*gl;
endtime->setDisplayFormat(tr("ddd MMMM d yyyy, h:mm ap","time format"));
endtime->setCalendarPopup(true);
connect(endtime,SIGNAL(dateTimeChanged(const QDateTime&)),this,SLOT(endTimeChanged(const QDateTime&)));
- if(event.id().isNull()){
+ if(event.id().isNull() && event.start().isNull()){
QDateTime tt(QDate::currentDate().addDays(1),QTime(20,0));//default: tomorrow 8pm
starttime->setDateTime(tt);
endtime->setDateTime(tt.addSecs(3600));
{
Q_OBJECT
public:
+ ///Mode for opening the editor window
+ enum class OpenMode{
+ /// Auto-Detect by Event-ID
+ Auto,
+ /// Edit the existing event
+ Edit,
+ /// Create a new event, if an ID is given use it as template only
+ Create
+ };
/**opens the editor, retrieves the event automatically if given*/
- MEventEditor(QWidget*,qint64 id=-1);
+ MEventEditor(QWidget*w,qint64 id=-1):MEventEditor(w,OpenMode::Auto,id){}
+ /**opens the editor*/
+ MEventEditor(QWidget*,OpenMode,qint64 id=-1);
private slots:
/**sends the event back to the database*/
void writeBack();
hl->addSpacing(5);
hl->addLayout(vl=new QVBoxLayout,0);
QPushButton*p;
- vl->addWidget(p=new QPushButton(tr("New Event...")),0);
- connect(p,SIGNAL(clicked()),this,SLOT(newEvent()));
+ vl->addWidget(p=new QPushButton(tr("New Event")),0);
p->setEnabled(req->hasRight(req->RCreateEvent));
- vl->addWidget(p=new QPushButton(tr("Details...")),0);
+ QMenu*m;
+ p->setMenu(m=new QMenu);
+ m->addAction(tr("New Event..."),this,SLOT(newEvent()));
+ m->addAction(tr("Clone Current Event..."),this,SLOT(cloneEvent()));
+
+ vl->addWidget(p=new QPushButton(tr("Details...")),0);
connect(p,SIGNAL(clicked()),this,SLOT(editEvent()));
p->setEnabled(req->hasRight(req->RGetEvent));
vl->addSpacing(15);
updateEvents();
}
+void MEventsTab::cloneEvent()
+{
+ int id;
+ QModelIndexList ilst=eventtable->selectionModel()->selectedIndexes();
+ if(ilst.size()<1)return;
+ QModelIndex idx=eventmodel->index(ilst[0].row(),0);
+ id=eventmodel->data(idx,Qt::UserRole).toInt();
+ if(id<0)return;
+ MEventEditor ed(this,MEventEditor::OpenMode::Create,id);
+ ed.exec();
+ updateEvents();
+}
+
void MEventsTab::editEvent()
{
int id;
private slots:
/**create a new event*/
void newEvent();
+ /**create a new event as copy*/
+ void cloneEvent();
/**edit existing event*/
void editEvent();
/**open event summary*/