QTfrontend/ui/page/pagevideos.cpp
changeset 7306 3cff5c769509
parent 7280 fd707afbc3a2
child 7353 0e55228e1303
equal deleted inserted replaced
7303:998128081b86 7306:3cff5c769509
    33 #include <QList>
    33 #include <QList>
    34 #include <QMessageBox>
    34 #include <QMessageBox>
    35 #include <QHeaderView>
    35 #include <QHeaderView>
    36 #include <QKeyEvent>
    36 #include <QKeyEvent>
    37 #include <QVBoxLayout>
    37 #include <QVBoxLayout>
       
    38 #include <QHBoxLayout>
    38 #include <QFileSystemWatcher>
    39 #include <QFileSystemWatcher>
    39 
    40 
    40 #include "hwconsts.h"
    41 #include "hwconsts.h"
    41 #include "pagevideos.h"
    42 #include "pagevideos.h"
    42 #include "igbox.h"
    43 #include "igbox.h"
    43 #include "libav_iteraction.h"
    44 #include "libav_iteraction.h"
    44 #include "gameuiconfig.h"
    45 #include "gameuiconfig.h"
    45 #include "recorder.h"
    46 #include "recorder.h"
    46 
    47 
       
    48 const int ThumbnailSize = 400;
       
    49 
    47 // columns in table with list of video files
    50 // columns in table with list of video files
    48 enum VideosColumns
    51 enum VideosColumns
    49 {
    52 {
    50     vcName,
    53     vcName,
    51     vcSize,
    54     vcSize,
    88 
    91 
    89 QLayout * PageVideos::bodyLayoutDefinition()
    92 QLayout * PageVideos::bodyLayoutDefinition()
    90 {
    93 {
    91     QGridLayout * pPageLayout = new QGridLayout();
    94     QGridLayout * pPageLayout = new QGridLayout();
    92     pPageLayout->setColumnStretch(0, 1);
    95     pPageLayout->setColumnStretch(0, 1);
    93     pPageLayout->setColumnStretch(1, 1);
    96     pPageLayout->setColumnStretch(1, 2);
       
    97     pPageLayout->setRowStretch(0, 1);
       
    98     pPageLayout->setRowStretch(1, 1);
    94 
    99 
    95     {
   100     {
    96         IconedGroupBox* pOptionsGroup = new IconedGroupBox(this);
   101         IconedGroupBox* pOptionsGroup = new IconedGroupBox(this);
    97         pOptionsGroup->setIcon(QIcon(":/res/graphicsicon.png"));
   102         pOptionsGroup->setIcon(QIcon(":/res/graphicsicon.png"));
    98         pOptionsGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
   103         pOptionsGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    99         pOptionsGroup->setTitle(QGroupBox::tr("Video recording options"));
   104         pOptionsGroup->setTitle(QGroupBox::tr("Video recording options"));
   100         QGridLayout * pOptLayout = new QGridLayout(pOptionsGroup);
   105         QGridLayout * pOptLayout = new QGridLayout(pOptionsGroup);
   101 
   106 
   102         // label for format
   107         // label for format
   103         QLabel *labelFormat = new QLabel(pOptionsGroup);
   108         QLabel *labelFormat = new QLabel(pOptionsGroup);
   197         pTableGroup->setTitle(QGroupBox::tr("Videos"));
   202         pTableGroup->setTitle(QGroupBox::tr("Videos"));
   198 
   203 
   199         QStringList columns;
   204         QStringList columns;
   200         columns << tr("Name");
   205         columns << tr("Name");
   201         columns << tr("Size");
   206         columns << tr("Size");
   202         columns << tr("...");
   207         columns << "";
   203 
   208 
   204         filesTable = new QTableWidget(pTableGroup);
   209         filesTable = new QTableWidget(pTableGroup);
   205         filesTable->setColumnCount(vcNumColumns);
   210         filesTable->setColumnCount(vcNumColumns);
   206         filesTable->setHorizontalHeaderLabels(columns);
   211         filesTable->setHorizontalHeaderLabels(columns);
   207         filesTable->setSelectionBehavior(QAbstractItemView::SelectRows);
   212         filesTable->setSelectionBehavior(QAbstractItemView::SelectRows);
   208         filesTable->setEditTriggers(QAbstractItemView::SelectedClicked);
   213         filesTable->setEditTriggers(QAbstractItemView::SelectedClicked);
   209         filesTable->verticalHeader()->hide();
   214         filesTable->verticalHeader()->hide();
   210 
   215 
   211         QHeaderView * header = filesTable->horizontalHeader();
   216         QHeaderView * header = filesTable->horizontalHeader();
   212         int length = header->length(); // FIXME
   217         header->setResizeMode(vcName, QHeaderView::ResizeToContents);
   213         // header->setResizeMode(QHeaderView::ResizeToContents);
   218         header->setResizeMode(vcSize, QHeaderView::Fixed);
   214         header->resizeSection(vcName, length/2);
   219         header->resizeSection(vcSize, 100);
   215         header->resizeSection(vcSize, length/4);
   220         header->setStretchLastSection(true);
   216         header->resizeSection(vcProgress, length/4);
       
   217 
   221 
   218         btnOpenDir = new QPushButton(QPushButton::tr("Open videos directory"), pTableGroup);
   222         btnOpenDir = new QPushButton(QPushButton::tr("Open videos directory"), pTableGroup);
   219 
   223 
   220         QVBoxLayout *box = new QVBoxLayout(pTableGroup);
   224         QVBoxLayout *box = new QVBoxLayout(pTableGroup);
   221         box->addWidget(filesTable);
   225         box->addWidget(filesTable);
   226 
   230 
   227     {
   231     {
   228         IconedGroupBox* pDescGroup = new IconedGroupBox(this);
   232         IconedGroupBox* pDescGroup = new IconedGroupBox(this);
   229         pDescGroup->setIcon(QIcon(":/res/graphicsicon.png"));
   233         pDescGroup->setIcon(QIcon(":/res/graphicsicon.png"));
   230         pDescGroup->setTitle(QGroupBox::tr("Description"));
   234         pDescGroup->setTitle(QGroupBox::tr("Description"));
   231         QGridLayout* pDescLayout = new QGridLayout(pDescGroup);
   235 
   232 
   236         QVBoxLayout* pDescLayout = new QVBoxLayout(pDescGroup);
       
   237         QHBoxLayout* pTopDescLayout = new QHBoxLayout(0);    // picture and text
       
   238         QHBoxLayout* pBottomDescLayout = new QHBoxLayout(0); // buttons
       
   239 
       
   240         // label with thumbnail picture
   233         labelThumbnail = new QLabel(pDescGroup);
   241         labelThumbnail = new QLabel(pDescGroup);
   234         pDescLayout->addWidget(labelThumbnail, 0, 0);
   242         labelThumbnail->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
       
   243         labelThumbnail->setStyleSheet(
       
   244                     "QFrame {"
       
   245                     "border: solid;"
       
   246                     "border-width: 3px;"
       
   247                     "border-color: #ffcc00;"
       
   248                     "border-radius: 4px;"
       
   249                     "}" );
       
   250         pTopDescLayout->addWidget(labelThumbnail);
   235 
   251 
   236         // label with file description
   252         // label with file description
   237         labelDesc = new QLabel(pDescGroup);
   253         labelDesc = new QLabel(pDescGroup);
   238         labelDesc->setAlignment(Qt::AlignLeft | Qt::AlignTop);
   254         labelDesc->setAlignment(Qt::AlignLeft | Qt::AlignTop);
   239         pDescLayout->addWidget(labelDesc, 0, 1);
   255         pTopDescLayout->addWidget(labelDesc);
   240 
   256 
   241         // buttons: play and delete
   257         // buttons: play and delete
   242         btnPlay = new QPushButton(QPushButton::tr("Play"), pDescGroup);
   258         btnPlay = new QPushButton(QPushButton::tr("Play"), pDescGroup);
   243         pDescLayout->addWidget(btnPlay, 1, 0);
   259         pBottomDescLayout->addWidget(btnPlay);
   244         btnDelete = new QPushButton(QPushButton::tr("Delete"), pDescGroup);
   260         btnDelete = new QPushButton(QPushButton::tr("Delete"), pDescGroup);
   245         pDescLayout->addWidget(btnDelete, 1, 1);
   261         pBottomDescLayout->addWidget(btnDelete);
       
   262 
       
   263         pDescLayout->addStretch(1);
       
   264         pDescLayout->addLayout(pTopDescLayout, 0);
       
   265         pDescLayout->addStretch(1);
       
   266         pDescLayout->addLayout(pBottomDescLayout, 0);
   246 
   267 
   247         pPageLayout->addWidget(pDescGroup, 0, 0);
   268         pPageLayout->addWidget(pDescGroup, 0, 0);
   248     }
   269     }
   249 
   270 
   250     return pPageLayout;
   271     return pPageLayout;
   541 
   562 
   542     // user has edited filename, so we should rename the file
   563     // user has edited filename, so we should rename the file
   543     VideoItem * item = nameItem(row);
   564     VideoItem * item = nameItem(row);
   544     QString oldName = item->name;
   565     QString oldName = item->name;
   545     QString newName = item->text();
   566     QString newName = item->text();
       
   567     if (!newName.contains('.'))
       
   568     {
       
   569         // user forgot an extension
       
   570         int pt = oldName.lastIndexOf('.');
       
   571         if (pt != -1)
       
   572             newName += oldName.right(oldName.length() - pt);
       
   573     }
   546     item->name = newName;
   574     item->name = newName;
   547     if (item->ready())
   575     if (item->ready())
   548     {
   576     {
   549         if(!cfgdir->rename("Videos/" + oldName, "Videos/" + newName))
   577         if(cfgdir->rename("Videos/" + oldName, "Videos/" + newName))
       
   578             updateDescription();
       
   579         else
   550         {
   580         {
   551             // unable to rename for some reason (maybe user entered incorrect name),
   581             // unable to rename for some reason (maybe user entered incorrect name),
   552             // therefore restore old name in cell
   582             // therefore restore old name in cell
   553             setName(item, oldName);
   583             setName(item, oldName);
   554         }
   584         }
   584     // add 'progress' item
   614     // add 'progress' item
   585     item = new QTableWidgetItem();
   615     item = new QTableWidgetItem();
   586     item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
   616     item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
   587     filesTable->setItem(row, vcProgress, item);
   617     filesTable->setItem(row, vcProgress, item);
   588 
   618 
       
   619    // filesTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
       
   620 
   589     return row;
   621     return row;
   590 }
   622 }
   591 
   623 
   592 VideoItem* PageVideos::nameItem(int row)
   624 VideoItem* PageVideos::nameItem(int row)
   593 {
   625 {
   595 }
   627 }
   596 
   628 
   597 void PageVideos::updateDescription()
   629 void PageVideos::updateDescription()
   598 {
   630 {
   599     VideoItem * item = nameItem(filesTable->currentRow());
   631     VideoItem * item = nameItem(filesTable->currentRow());
       
   632     if (!item)
       
   633     {
       
   634         labelDesc->clear();
       
   635         labelThumbnail->clear();
       
   636         return;
       
   637     }
       
   638 
   600     QString desc = "";
   639     QString desc = "";
   601     if (item)
   640     desc += item->name + "\n";
   602     {
   641 
   603         QString t = item->name;
   642     QString thumbName = "";
   604         desc += item->name + "\n";
   643 
   605         // t.replace(".mp4", ".bmp");
   644     if (item->ready())
   606         // QMessageBox::information(this, "1", cfgdir->absoluteFilePath("Screenshots/" + t));
   645     {
   607        //  m_pic.load(cfgdir->absoluteFilePath("Screenshots/" + t));
   646         QString path = item->path();
   608        //  m_pic = m_pic.scaledToWidth(400);
   647         desc += tr("\nSize: ") + FileSizeStr(path) + "\n";
   609         // m_thumbnail.setPixmap(m_pic);
   648         if (item->desc == "")
   610 
   649             item->desc = LibavIteraction::instance().getFileInfo(path);
       
   650         desc += item->desc;
       
   651 
       
   652         // extract thumbnail name fron description
       
   653         int prefixBegin = desc.indexOf("prefix[");
       
   654         int prefixEnd = desc.indexOf("]prefix");
       
   655         if (prefixBegin != -1 && prefixEnd != -1)
       
   656         {
       
   657             QString prefix = desc.mid(prefixBegin + 7, prefixEnd - (prefixBegin + 7));
       
   658             desc.remove(prefixBegin, prefixEnd + 7 - prefixBegin);
       
   659             thumbName = prefix;
       
   660         }
       
   661     }
       
   662     else
       
   663         desc += tr("(in progress...)");
       
   664 
       
   665     if (thumbName.isEmpty())
       
   666     {
   611         if (item->ready())
   667         if (item->ready())
       
   668             thumbName = item->name;
       
   669         else
       
   670             thumbName = item->pRecorder->name;
       
   671         // remove extension
       
   672         int pt = thumbName.lastIndexOf('.');
       
   673         if (pt != -1)
       
   674             thumbName.truncate(pt);
       
   675     }
       
   676 
       
   677     if (!thumbName.isEmpty())
       
   678     {
       
   679         thumbName = cfgdir->absoluteFilePath("VideoTemp/" + thumbName);
       
   680         if (picThumbnail.load(thumbName + ".png") || picThumbnail.load(thumbName + ".bmp"))
   612         {
   681         {
   613             QString path = item->path();
   682             if (picThumbnail.width() > picThumbnail.height())
   614             desc += tr("\nSize: ") + FileSizeStr(path) + "\n";
   683                 picThumbnail = picThumbnail.scaledToWidth(ThumbnailSize);
   615             if (item->desc == "")
   684             else
   616                 item->desc = LibavIteraction::instance().getFileInfo(path);
   685                 picThumbnail = picThumbnail.scaledToHeight(ThumbnailSize);
   617             desc += item->desc;
   686             labelThumbnail->setMaximumSize(picThumbnail.size());
       
   687             labelThumbnail->setPixmap(picThumbnail);
   618         }
   688         }
   619         else
   689         else
   620             desc += tr("(in progress...)");
   690             labelThumbnail->clear();
   621     }
   691     }
   622     labelDesc->setText(desc);
   692     labelDesc->setText(desc);
   623 }
   693 }
   624 
   694 
   625 // user selected another cell, so we should change description
   695 // user selected another cell, so we should change description