make description rich text enabled
authorKonrad Rosenbaum <konrad@silmor.de>
Tue, 12 Jan 2021 19:02:51 +0000 (20:02 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Tue, 12 Jan 2021 19:02:51 +0000 (20:02 +0100)
kino.cpp
kino.h

index 206c215..0274b6d 100644 (file)
--- a/kino.cpp
+++ b/kino.cpp
@@ -24,6 +24,7 @@
 #include <QStandardItemModel>
 #include <QStandardPaths>
 #include <QStorageInfo>
+#include <QTableView>
 #include <QTabWidget>
 #include <QTextBrowser>
 #include <QTextEdit>
@@ -106,7 +107,7 @@ Kino::Kino(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f)
        connect(mPicture,SIGNAL(resized()),this,SLOT(reImage()),Qt::QueuedConnection);
        connect(this,SIGNAL(updateImage()),this,SLOT(reImage()),Qt::QueuedConnection);
        csplit->setStretchFactor(0,15);
-       csplit->addWidget(mText=new QLabel("Description"));
+       csplit->addWidget(mText=new QTextBrowser);
        mText->setFrameShape(QFrame::StyledPanel);
        csplit->setStretchFactor(1,3);
        split->setSizes(QList<int>()<<100<<500);
@@ -121,6 +122,7 @@ Kino::Kino(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f)
        populate();
 
        mrecent=set.value("recent").toStringList();
+    mhistory=set.value("history").value<QList<History_s>>();
        redoRecent();
 }
 
@@ -137,6 +139,7 @@ void Kino::sync()
        for(auto split:findChildren<QSplitter*>())
                set.setValue("splitter/"+split->objectName(),split->saveState());
        set.setValue("recent",QVariant::fromValue(mrecent));
+    set.setValue("history",QVariant::fromValue(mhistory));
 }
 
 void Kino::findRoot()
@@ -238,7 +241,10 @@ void Kino::redoRecent()
                auto act=mGoto->addAction(ent.longLabel(),this,SLOT(gotoRecent()),QKeySequence(QString("Alt+%1").arg(i+1)));
         act->setData(mrecent[i]);
         act->setToolTip(QString("Video: %1\nVolume: %3\n\n%2").arg(ent.directory()).arg(ent.description()).arg(vol.label()));
+        act->setShortcutVisibleInContextMenu(true);
        }
+       mGoto->addSeparator();
+    mGoto->addAction("&Show History...",this,SLOT(showHistory()),QKeySequence("Alt+S"))->setShortcutVisibleInContextMenu(true);
 }
 
 
@@ -317,6 +323,8 @@ void Kino::playMedia(bool full)
                if(mrecent.contains(p))
                        mrecent.removeAll(p);
                mrecent.prepend(p);
+        mhistory.prepend(p);
+        while(mhistory.size()>100)mhistory.removeLast();
         sync();
                redoRecent();
        }
@@ -337,16 +345,19 @@ static inline QModelIndex findModelItem(QStandardItemModel*model,QString id,QMod
        return QModelIndex();
 }
 
-void Kino::gotoRecent()
+void Kino::gotoRecent(QString id)
 {
-       //get action
-       QAction*act=qobject_cast<QAction*>(sender());
-       if(act==nullptr){
-               qDebug()<<"WARNING: gotoRecent called without back-link to action!";
-               return;
-       }
+       //get action (skip if id has been provided - see showHistory())
+    if(id.isEmpty()){
+        QAction*act=qobject_cast<QAction*>(sender());
+        if(act==nullptr){
+            qDebug()<<"WARNING: gotoRecent called without back-link to action!";
+            return;
+        }
+        id=act->data().toString();
+    }
        //find entry in tree
-       QModelIndex idx=findModelItem(mModel,act->data().toString());
+       QModelIndex idx=findModelItem(mModel,id);
        if(idx.isValid()){
                mTree->scrollTo(idx);
                QItemSelectionModel* sel=mTree->selectionModel();
@@ -490,12 +501,66 @@ void Kino::about()
        d.exec();
 }
 
+void Kino::showHistory()
+{
+    //create GUI
+    QDialog d(this);
+    d.resize(800,600);
+    d.setSizeGripEnabled(true);
+    QVBoxLayout*vl;
+    d.setLayout(vl=new QVBoxLayout);
+    QTableView*tv;
+    QStandardItemModel*sm;
+    vl->addWidget(tv=new QTableView,1);
+    tv->setModel(sm=new QStandardItemModel(&d));
+    QHBoxLayout*hl;
+    vl->addLayout(hl=new QHBoxLayout,0);
+    hl->addStretch(1);
+    QPushButton*p;
+    hl->addWidget(p=new QPushButton("Goto..."));
+    connect(p,SIGNAL(clicked()),&d,SLOT(accept()));
+    hl->addWidget(p=new QPushButton("Close"));
+    connect(p,SIGNAL(clicked()),&d,SLOT(reject()));
+    //fill table
+    sm->setHorizontalHeaderLabels(QStringList()<<"Film"<<"Volume"<<"Time");
+    sm->insertRows(0,mhistory.size());
+    for(int i=0;i<mhistory.size();i++){
+        // find entry
+        auto &vol=getVolume(mhistory[i].id);
+        const auto &ent=getEntry(vol,mhistory[i].id);
+        //display
+        sm->setData(sm->index(i,0),ent.longLabel(),Qt::DisplayRole);
+        sm->setData(sm->index(i,0),mhistory[i].id,Qt::UserRole);
+        sm->setData(sm->index(i,1),vol.label(),Qt::DisplayRole);
+        sm->setData(sm->index(i,2),mhistory[i].when,Qt::DisplayRole);
+    }
+    tv->resizeColumnsToContents();
+    tv->setEditTriggers(QAbstractItemView::NoEditTriggers);
+    tv->setSelectionBehavior(QAbstractItemView::SelectRows);
+    //wait for user
+    if(d.exec()==QDialog::Accepted){//Goto...
+        //get selection
+        auto smd=tv->selectionModel();
+        QModelIndexList idxl=smd->selectedIndexes();
+        QModelIndex idx;
+        if(idxl.size()>0)idx=idxl[0];
+        if(!idx.isValid())idx=smd->currentIndex();
+        if(!idx.isValid())return;
+        //get ID and goto
+        gotoRecent(sm->data(sm->index(idx.row(),0),Qt::UserRole).toString());
+    }//else Close...
+}
+
 
 int main(int ac,char**av)
 {
        qRegisterMetaType<QPair<qint64,qint64>>();
        qRegisterMetaTypeStreamOperators<QPair<qint64,qint64>>();
-       QCoreApplication::setOrganizationName("Silmor");
+    qRegisterMetaType<History_s>();
+    qRegisterMetaType<QList<History_s>>();
+    qRegisterMetaTypeStreamOperators<History_s>();
+    qRegisterMetaTypeStreamOperators<QList<History_s>>();
+    QCoreApplication::setOrganizationName("Silmor");
        QCoreApplication::setOrganizationDomain("silmor.de");
        QCoreApplication::setApplicationName("Kino");
        QApplication app(ac,av);
diff --git a/kino.h b/kino.h
index 32688e2..af85ad9 100644 (file)
--- a/kino.h
+++ b/kino.h
@@ -10,6 +10,7 @@
 #include <QUuid>
 #include <QList>
 #include <QLabel>
+#include <QDateTime>
 
 class QLabel;
 class QStandardItemModel;
@@ -17,9 +18,22 @@ class QModelIndex;
 class QItemSelection;
 class QTreeView;
 class QMenu;
+class QTextBrowser;
 
 #include "volume.h"
 
+///Helper structure for history storage
+struct History_s
+{
+    History_s()=default;
+    History_s(const QString&s):id(s),when(QDateTime::currentDateTime()){}
+    History_s(const History_s&)=default;
+    History_s(History_s&&)=default;
+    History_s& operator=(const History_s&)=default;
+    History_s& operator=(History_s&&)=default;
+    QString id;QDateTime when;
+};
+
 ///Main window
 class Kino:public QWidget
 {
@@ -37,7 +51,7 @@ private slots:
        ///play media via play button
        void playMedia(bool full=true);
        ///goto recently played disc
-       void gotoRecent();
+       void gotoRecent(QString id=QString());
        ///called when selection changes
        void select();
        ///repaints the current image, call updateImage instead
@@ -48,6 +62,8 @@ private slots:
        void findRoot();
        ///about dialog
        void about();
+    ///history table
+    void showHistory();
 signals:
        ///signals to repaint the image
        void updateImage();
@@ -67,7 +83,7 @@ private:
 
        ///reformats the Goto button menu
        void redoRecent();
-    
+
     ///synchronizes status data (geometry, list of recents plays,...)
     void sync();
 
@@ -75,7 +91,8 @@ private:
        bool play(QString,bool);
 
        QStandardItemModel *mModel=0;
-       QLabel *mPicture=0,*mText=0;
+       QLabel *mPicture=0;
+    QTextBrowser*mText=0;
        QTreeView*mTree=0;
        QMenu*mGoto=0;
        QList<Volume> mvolumes;
@@ -85,6 +102,41 @@ private:
        QSize mlastimagesize;
        QString mlastimage;
        QAction*mplayaction=0,*meditaction=0;
+    QList<History_s>mhistory;
 };
 
+Q_DECLARE_METATYPE(History_s);
+Q_DECLARE_METATYPE(QList<History_s>);
+
+inline QDataStream& operator<<(QDataStream&strm,const History_s&h)
+{
+    strm<<h.id<<h.when;
+    return strm;
+}
+inline QDataStream& operator>>(QDataStream&strm,History_s&h)
+{
+    strm>>h.id>>h.when;
+    return strm;
+}
+
+inline QDataStream& operator<<(QDataStream&strm,const QList<History_s>&hl)
+{
+    strm<<hl.size();
+    for(const auto&h:hl)
+        strm<<h;
+    return strm;
+}
+inline QDataStream& operator>>(QDataStream&strm,QList<History_s>&hl)
+{
+    hl.clear();
+    int sz;
+    strm>>sz;
+    for(int i=0;i<sz;i++){
+        History_s h;
+        strm>>h;
+        hl.append(h);
+    }
+    return strm;
+}
+
 #endif