From 9ea50605be980867979dca65abb9041a153b2a9a Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Sun, 29 May 2016 14:10:32 +0200 Subject: [PATCH] refactor event overview, first draft of enabling HTML, draft of pattern --- iface/msinterface.cpp | 10 +++ iface/msinterface.h | 3 + src/mwin/eventstab.cpp | 134 +++----------------------------- src/mwin/eventstab.h | 7 +- src/widgets/eventview.cpp | 185 +++++++++++++++++++++++++++++++++++++++++++++ src/widgets/eventview.h | 45 +++++++++++ src/widgets/widgets.pri | 6 +- 7 files changed, 262 insertions(+), 128 deletions(-) create mode 100644 src/widgets/eventview.cpp create mode 100644 src/widgets/eventview.h diff --git a/iface/msinterface.cpp b/iface/msinterface.cpp index 8d97953..5a3fd1e 100644 --- a/iface/msinterface.cpp +++ b/iface/msinterface.cpp @@ -287,3 +287,13 @@ bool MSInterface::checkFlags(const QStringList& fl) const //survived all tests return true; } + +QUrl MSInterface::parentUrl() const +{ + QUrl parent=url(); + parent.setFragment(QString()); + parent.setQuery(QString()); + QString path=parent.path(); + if(path==QString() || path.endsWith('/'))return parent; + parent.setPath(path.left(path.lastIndexOf('/')+1)); +} diff --git a/iface/msinterface.h b/iface/msinterface.h index f271ab6..7ce3475 100644 --- a/iface/msinterface.h +++ b/iface/msinterface.h @@ -98,6 +98,9 @@ class MSIFACE_EXPORT MSInterface:public MInterface ///return all flags of the current user QStringList allFlags()const{return userflags;} + + ///return the parent directory of the base URL + QUrl parentUrl()const; ///return application main data directory static QString appDataDir(); diff --git a/src/mwin/eventstab.cpp b/src/mwin/eventstab.cpp index 4afafe8..a6240e6 100644 --- a/src/mwin/eventstab.cpp +++ b/src/mwin/eventstab.cpp @@ -13,6 +13,7 @@ #include "centbox.h" #include "eventedit.h" #include "eventsummary.h" +#include "eventview.h" #include "main.h" #include "misc.h" #include "msinterface.h" @@ -49,6 +50,12 @@ #include #include #include +#include +#include +#include +#include + + MEventsTab::MEventsTab(QString pk) { @@ -57,7 +64,7 @@ MEventsTab::MEventsTab(QString pk) setObjectName("eventstab"); //Event tab - QVBoxLayout*vl;QHBoxLayout*hl; + QVBoxLayout*vl; setLayout(vl=new QVBoxLayout); QSplitter*split; vl->addWidget(split=new QSplitter); @@ -70,38 +77,10 @@ MEventsTab::MEventsTab(QString pk) eventtable->setSortingEnabled(true); eventmodel->setSortRole(SortRole); connect(eventtable->selectionModel(),SIGNAL(selectionChanged(QItemSelection,QItemSelection)),this,SLOT(updateDetails())); - split->addWidget(eventdetail=new QTextBrowser); - eventdetail->setReadOnly(true); - connect(eventdetail,SIGNAL(anchorClicked(QUrl)),this,SLOT(eventOrderTicketUrl(QUrl))); - eventdetail->setOpenExternalLinks(false); - eventdetail->setOpenLinks(false); -/* hl->addSpacing(5); - hl->addLayout(vl=new QVBoxLayout,0); - QPushButton*p; - vl->addWidget(p=new QPushButton(tr("New Event")),0); - p->setEnabled(req->hasRight(req->RCreateEvent)); - QMenu*m; - p->setMenu(m=new QMenu); - m->addAction(tr("New Event..."),this,SLOT(newEvent())); - m->addAction(tr("Clone Current Event..."),this,SLOT(cloneEvent())); + split->addWidget(eventdetail=new MEventView); + connect(eventdetail,SIGNAL(eventOrderTicket(qint64,qint64)),this,SIGNAL(eventOrderTicket(qint64,qint64))); + connect(eventdetail,SIGNAL(eventOrderTicket()),this,SIGNAL(eventOrderTicket())); - vl->addWidget(p=new QPushButton(tr("Details...")),0); - connect(p,SIGNAL(clicked()),this,SLOT(editEvent())); - p->setEnabled(req->hasRight(req->RGetEvent)); - vl->addSpacing(15); - vl->addWidget(p=new QPushButton(tr("Order Ticket...")),0); - connect(p,SIGNAL(clicked()),this,SIGNAL(eventOrderTicket())); - p->setEnabled(req->hasRight(req->RCreateOrder)||req->hasRight(req->RCreateReservation)); - vl->addSpacing(15); - vl->addWidget(p=new QPushButton(tr("Event Summary...")),0); - connect(p,SIGNAL(clicked()),this,SLOT(eventSummary())); - p->setEnabled(req->hasRight(req->RGetEventSummary)); - vl->addSpacing(15); - vl->addWidget(p=new QPushButton(tr("Cancel Event...")),0); - p->setEnabled(req->hasRight(req->RCancelEvent)); - connect(p,SIGNAL(clicked()),this,SLOT(eventCancel())); - vl->addStretch(10); -*/ //fill tables if(req->hasRight(req->RGetAllEvents)){ updateEvents(); @@ -204,8 +183,7 @@ MEventsTab::~MEventsTab() void MEventsTab::updateDetails() { //clear - eventdetail->clearHistory(); - eventdetail->clear(); + eventdetail->clearEvent(); //get selection QModelIndexList ilst=eventtable->selectionModel()->selectedIndexes(); if(ilst.size()<1)return; @@ -213,93 +191,7 @@ void MEventsTab::updateDetails() //get event MOEvent event=eventmodel->data(idx,ObjectRole).value(); if(!event.isValid())return; - //generate HTML - QString detail="

"+htmlize(event.title())+"

\n"; - detail+=tr("Artist: %1").arg(htmlize(event.artist().value().name()))+"

\n"; - detail+=tr("Starttime: %1").arg(htmlize(event.startTimeString()))+"
\n"; - detail+=tr("Endtime: %1").arg(htmlize(event.startTimeString()))+"

\n"; - detail+=tr("Room: %1").arg(htmlize(event.room()))+"
\n"; - detail+=tr("Seats: %1 max. (%2 sold out; %3 reserved; %4 free)").arg(event.capacity()).arg(event.amountSold()).arg(event.amountReserved()).arg(event.amountFree())+"

\n"; - - const QString bgsold=tr("

Sold Out!
","Colored display for sold out tickets"); - const QString bgavail=tr("
","Colored display for ordering tickets"); - const QString bghide=tr("
Unable to sell.
","Colored display for tickets unavailable to this user"); - - const bool showevent=req->checkFlags(event.flags()); - if(showevent) - detail+=event.amountFree()>0?bgavail.arg(QString("order:?ev=%1").arg(event.id())):bgsold; - else - detail+=bghide; - detail+="

"+tr("Prices")+"

\n"; - detail+="" - "\n"; - QListprices=event.price(); - qSort(prices.begin(),prices.end(),[](const MOEventPrice&p1,const MOEventPrice&p2){return p1.prio()checkFlags(ctg.flags())) - detail+=""; - } - detail+="
"+tr("Category")+""+tr("Price")+""+tr("Available")+""+tr("Max. Seats")+""+tr("Order")+"
"+ - (avail>0? - bgavail.arg(QString("order:?ev=%1&pr=%2").arg(event.id()).arg(ctg.pricecategoryid())) - :bgsold); - else - detail+=""+bghide; - detail+="

\n"; - - detail+="

"+tr("Description")+"

\n"+event.description()+"

\n"; - detail+="

"+tr("Comment")+"

\n"+htmlize(event.comment()); - //set value - eventdetail->setHtml(detail); -} - -void MEventsTab::eventOrderTicketUrl(const QUrl &url) -{ - //check whether it is order URL - if(url.scheme()=="order"){ - QUrlQuery query(url); - if(query.hasQueryItem("ev")){ - bool b=false; - qint64 evid=query.queryItemValue("ev").toLongLong(&b); - if(!b || evid<0){ - qDebug()<<"ordering tickets for current event (invalid EvID)..."; - emit eventOrderTicket(); - return; - } - qint64 prid=-1; - if(query.hasQueryItem("pr")){ - prid=query.queryItemValue("pr").toLongLong(&b); - if(!b)prid=-1; - } - qDebug()<<"ordering tickets for event"<url().resolved(url); - qDebug()<<"Relative URL"<url(); - qDebug()<<" ...opening"<setEvent(event); } void MEventsTab::newEvent() diff --git a/src/mwin/eventstab.h b/src/mwin/eventstab.h index 3759adc..1a10383 100644 --- a/src/mwin/eventstab.h +++ b/src/mwin/eventstab.h @@ -29,7 +29,7 @@ class QSpinBox; class QStandardItemModel; class QTabWidget; class QTableView; -class QTextBrowser; +class MEventView; class MSInterface; @@ -82,9 +82,6 @@ class MEventsTab:public QWidget /// \param multi true if multiple IDs can be selected, false if only one can be selec ted void selectEventIds(QList&eids,bool multi=true)const; - ///order ticket from URL click - void eventOrderTicketUrl(const QUrl&); - signals: /**order ticket from event tab*/ void eventOrderTicket(); @@ -97,7 +94,7 @@ class MEventsTab:public QWidget //widgets QTableView*eventtable; QStandardItemModel*eventmodel; - QTextBrowser*eventdetail; + MEventView*eventdetail; //event list QAction*showoldevents; //refresh timers diff --git a/src/widgets/eventview.cpp b/src/widgets/eventview.cpp new file mode 100644 index 0000000..e77bb5a --- /dev/null +++ b/src/widgets/eventview.cpp @@ -0,0 +1,185 @@ +// +// C++ Implementation: event list tab +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2007-2013 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "eventview.h" +#include "misc.h" +#include "msinterface.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +MEventView::MEventView ( QWidget* parent ) : QTextBrowser ( parent ) +{ + setReadOnly(true); + connect(this,SIGNAL(anchorClicked(QUrl)),this,SLOT(handleClick(QUrl))); + setOpenExternalLinks(false); + setOpenLinks(false); + qDebug()<<"Setting path"<parentUrl()<<"for URL"<url(); + setSearchPaths(QStringList()<parentUrl().toString()); + resetPattern(); +} + + +QVariant MEventView::loadResource ( int type, const QUrl& name ) +{ + Q_UNUSED(type); + qDebug()<<"Loading Resource"<url().resolved(name); + QNetworkAccessManager nam; + connect(&nam,SIGNAL(sslErrors(QNetworkReply*,QList)),req,SLOT(sslErrors(QNetworkReply*,QList))); + QNetworkReply*rpl= nam.get(QNetworkRequest(url)); + qDebug()<<"Trying to GET"<readAll(); + qDebug()<<"...got"<\n"; + detail+=tr("Artist: %1").arg(htmlize(event.artist().value().name()))+"

\n"; + detail+=tr("Starttime: %1").arg(htmlize(event.startTimeString()))+"
\n"; + detail+=tr("Endtime: %1").arg(htmlize(event.endTimeString()))+"

\n"; + detail+=tr("Room: %1").arg(htmlize(event.room()))+"
\n"; + detail+=tr("Seats: %1 max. (%2 sold out; %3 reserved; %4 free)").arg(event.capacity()).arg(event.amountSold()).arg(event.amountReserved()).arg(event.amountFree())+"

\n"; + + const QString bgsold=tr("

Sold Out!
","Colored display for sold out tickets"); + const QString bgavail=tr("
","Colored display for ordering tickets"); + const QString bghide=tr("
Unable to sell.
","Colored display for tickets unavailable to this user"); + + const bool showevent=req->checkFlags(event.flags()); + if(showevent) + detail+=event.amountFree()>0?bgavail.arg(QString("order:?ev=%1").arg(event.id())):bgsold; + else + detail+=bghide; + detail+="

"+tr("Prices")+"

\n"; + detail+="" + "\n"; + QListprices=event.price(); + qSort(prices.begin(),prices.end(),[](const MOEventPrice&p1,const MOEventPrice&p2){return p1.prio()checkFlags(ctg.flags())) + detail+=""; + } + detail+="
"+tr("Category")+""+tr("Price")+""+tr("Available")+""+tr("Max. Seats")+""+tr("Order")+"
"+ + (avail>0? + bgavail.arg(QString("order:?ev=%1&pr=%2").arg(event.id()).arg(ctg.pricecategoryid())) + :bgsold); + else + detail+=""+bghide; + detail+="

\n"; + + detail+="

"+tr("Description")+"

\n"+event.description()+"

\n"; + detail+="

"+tr("Comment")+"

\n"; + QString comment=event.comment(); + if(!comment.trimmed().startsWith(""))comment=htmlize(comment); + detail+=comment; + //set value + setHtml(detail); +} + +void MEventView::handleClick(const QUrl &url) +{ + //check whether it is order URL + if(url.scheme()=="order"){ + QUrlQuery query(url); + if(query.hasQueryItem("ev")){ + bool b=false; + qint64 evid=query.queryItemValue("ev").toLongLong(&b); + if(!b || evid<0){ + qDebug()<<"ordering tickets for current event (invalid EvID)..."; + emit eventOrderTicket(); + return; + } + qint64 prid=-1; + if(query.hasQueryItem("pr")){ + prid=query.queryItemValue("pr").toLongLong(&b); + if(!b)prid=-1; + } + qDebug()<<"ordering tickets for event"<url().resolved(url); + qDebug()<<"Relative URL"<url(); + qDebug()<<" ...opening"<{event.name|html}\n" + "Artist: {event.artist|html}

\n" + "Starttime: {event.startTimeString}
\n" + "Endtime: {event.endTimeString}

\n" + "Room: {event.room|html}
\n" + "Seats: {event.capacity} max. ({event.amountSold} sold out; {event.amountReserved} reserved; {event.amountFree} free)

\n" + "{% if(event.haveAccess) %}\n" + + "{% endif %}" + ); +} diff --git a/src/widgets/eventview.h b/src/widgets/eventview.h new file mode 100644 index 0000000..6fa58e5 --- /dev/null +++ b/src/widgets/eventview.h @@ -0,0 +1,45 @@ +// +// C++ Interface: event view` +// +// Description: widget for displaying event details +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_EVENTVIEW_H +#define MAGICSMOKE_EVENTVIEW_H + +#include + +#include + +///Event Viewer +class MEventView:public QTextBrowser +{ + Q_OBJECT +public: + explicit MEventView ( QWidget* parent = 0 ); + QVariant loadResource(int type, const QUrl & name)override; + +public slots: + void setEvent(MOEvent); + void clearEvent(); + void setPattern(QString); + void resetPattern(); +private slots: + void handleClick(const QUrl&); +signals: + /**order ticket from event tab*/ + void eventOrderTicket(); + /**order ticket from event tab*/ + void eventOrderTicket(qint64,qint64); +private: + QString mPattern; +}; + + +#endif diff --git a/src/widgets/widgets.pri b/src/widgets/widgets.pri index ac92607..40f1ed2 100644 --- a/src/widgets/widgets.pri +++ b/src/widgets/widgets.pri @@ -2,12 +2,14 @@ HEADERS += \ widgets/centbox.h \ widgets/listview.h \ widgets/treeview.h \ - widgets/barcodeline.h + widgets/barcodeline.h \ + widgets/eventview.h SOURCES += \ widgets/centbox.cpp \ widgets/listview.cpp \ widgets/treeview.cpp \ - widgets/barcodeline.cpp + widgets/barcodeline.cpp \ + widgets/eventview.cpp INCLUDEPATH += ./widgets -- 1.7.2.5