summaryrefslogtreecommitdiffstats
path: root/archiveitemcoveredit.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2010-05-29 12:40:45 +0200
committerArno <am@disconnect.de>2010-05-29 12:40:45 +0200
commitd95e3f02d6615854547bded419de81395b28c2c5 (patch)
tree8f550fda5daa1fe6b27469a8b1ead04b9a364d73 /archiveitemcoveredit.cpp
parent98903de8351e1f78a057febe0bb996223a238d56 (diff)
downloadSheMov-d95e3f02d6615854547bded419de81395b28c2c5.tar.gz
SheMov-d95e3f02d6615854547bded419de81395b28c2c5.tar.bz2
SheMov-d95e3f02d6615854547bded419de81395b28c2c5.zip
Implemented ArchiveItemCoverEdit
Implemented Widget in preparation for the new ArchiveItemEditDialog. It's still quite convoluted, but I can't think of a better way to do this.
Diffstat (limited to 'archiveitemcoveredit.cpp')
-rw-r--r--archiveitemcoveredit.cpp214
1 files changed, 214 insertions, 0 deletions
diff --git a/archiveitemcoveredit.cpp b/archiveitemcoveredit.cpp
new file mode 100644
index 0000000..41672d7
--- /dev/null
+++ b/archiveitemcoveredit.cpp
@@ -0,0 +1,214 @@
+/*
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version
+ 2 of the License, or (at your option) any later version.
+*/
+
+#include <QLabel>
+#include <QVBoxLayout>
+#include <QGridLayout>
+#include <QSignalMapper>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QCheckBox>
+#include <QFileDialog>
+#include <QSettings>
+#include <QSettings>
+#include <QFileInfo>
+
+#include <algorithm>
+
+#include "archiveitemcoveredit.h"
+#include "pictureviewer.h"
+#include "coveritem.h"
+#include "helper.h"
+
+ArchiveItemCoverEdit::ArchiveItemCoverEdit(QWidget *parent) : QWidget(parent) {
+ //Widget setup
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mPicViewer = new PictureViewer;
+ QSignalMapper *viewMapper = new QSignalMapper(this);
+ QSignalMapper *browseMapper = new QSignalMapper(this);
+ QSignalMapper *unlockMapper = new QSignalMapper(this);
+ QGridLayout *coverLayout = new QGridLayout;
+
+ //Warning
+ QLabel *descriptionLabel = new QLabel(tr("Edit covers of movie - if the movie already has covers you have to unlock the specific cover for changing it. Then click browse to select a new cover. WARNING: The old cover will be deleted from archive if you submit the changes!"));
+ descriptionLabel->setBackgroundRole(QPalette::Light);
+ descriptionLabel->setFrameStyle(QFrame::Box);
+ mainLayout->addWidget(descriptionLabel);
+
+ //Front cover
+ QLabel *frontCoverLabel = new QLabel(tr("Front cover"));
+ coverLayout->addWidget(frontCoverLabel, 0, 0);
+ mFrontCover = new QLineEdit;
+ mInitialValue.insert(mFrontCover, QString());
+ coverLayout->addWidget(mFrontCover);
+ mBrowseFront = new QPushButton(tr("Browse..."));
+ connect(mBrowseFront, SIGNAL(clicked()), browseMapper, SLOT(map()));
+ browseMapper->setMapping(mBrowseFront, mFrontCover);
+ coverLayout->addWidget(mBrowseFront, 0, 1);
+ mViewFront = new QPushButton(tr("View"));
+ connect(mViewFront, SIGNAL(clicked()), viewMapper, SLOT(map()));
+ viewMapper->setMapping(mViewFront, mFrontCover);
+ coverLayout->addWidget(mViewFront, 0, 2);
+ mUnlockFront = new QCheckBox;
+ mCheckboxTexts.insert(mUnlockFront, qMakePair(tr("Unlock front cover"), tr("Reset and lock front cover")));
+ mUnlockFront->setText(mCheckboxTexts.value(mUnlockFront).first);
+ mLineEditMapping.insert(mFrontCover, mUnlockFront);
+ mBrowseMap.insert(mUnlockFront, mBrowseFront);
+ connect(mUnlockFront, SIGNAL(stateChanged(int)), unlockMapper, SLOT(map()));
+ unlockMapper->setMapping(mUnlockFront, mFrontCover);
+ coverLayout->addWidget(mUnlockFront, 1, 1, 0, 2, Qt::AlignRight);
+
+ //Back cover
+ QLabel *backCoverLabel = new QLabel(tr("Back cover"));
+ coverLayout->addWidget(backCoverLabel, 2, 0);
+ mBackCover = new QLineEdit;
+ mInitialValue.insert(mBackCover, QString());
+ coverLayout->addWidget(mBackCover);
+ mBrowseBack = new QPushButton(tr("Browse..."));
+ connect(mBrowseBack, SIGNAL(clicked()), browseMapper, SLOT(map()));
+ browseMapper->setMapping(mBrowseBack, mBackCover);
+ coverLayout->addWidget(mBrowseBack, 2, 1);
+ mViewBack = new QPushButton(tr("View"));
+ connect(mViewBack, SIGNAL(clicked()), viewMapper, SLOT(map()));
+ viewMapper->setMapping(mViewBack, mBackCover);
+ coverLayout->addWidget(mViewBack, 2, 2);
+ mUnlockBack = new QCheckBox;
+ mCheckboxTexts.insert(mUnlockBack, qMakePair(tr("Unlock back cover"), tr("Reset and lock back cover")));
+ mUnlockBack->setText(mCheckboxTexts.value(mUnlockBack).first);
+ mLineEditMapping.insert(mBackCover, mUnlockBack);
+ mBrowseMap.insert(mUnlockBack, mBrowseBack);
+ connect(mUnlockBack, SIGNAL(stateChanged(int)), unlockMapper, SLOT(map()));
+ unlockMapper->setMapping(mUnlockBack, mBackCover);
+ coverLayout->addWidget(mUnlockBack, 3, 1, 0, 2, Qt::AlignRight);
+
+ //General cover
+ QLabel *generalCoverLabel = new QLabel(tr("General cover"));
+ coverLayout->addWidget(generalCoverLabel, 4, 0);
+ mGeneralCover = new QLineEdit;
+ mInitialValue.insert(mGeneralCover, QString());
+ coverLayout->addWidget(mGeneralCover);
+ mBrowseGeneral = new QPushButton(tr("Browse..."));
+ connect(mBrowseGeneral, SIGNAL(clicked()), browseMapper, SLOT(map()));
+ browseMapper->setMapping(mBrowseGeneral, mGeneralCover);
+ coverLayout->addWidget(mBrowseGeneral, 4, 1);
+ mViewGeneral = new QPushButton(tr("View"));
+ connect(mViewGeneral, SIGNAL(clicked()), viewMapper, SLOT(map()));
+ viewMapper->setMapping(mViewGeneral, mGeneralCover);
+ coverLayout->addWidget(mViewGeneral, 4, 2);
+ mUnlockGeneral = new QCheckBox;
+ mCheckboxTexts.insert(mUnlockGeneral, qMakePair(tr("Unlock general cover"), tr("Reset and lock general cover")));
+ mUnlockGeneral->setText(mCheckboxTexts.value(mUnlockGeneral).first);
+ mLineEditMapping.insert(mGeneralCover, mUnlockGeneral);
+ mBrowseMap.insert(mUnlockGeneral, mBrowseGeneral);
+ connect(mUnlockGeneral, SIGNAL(stateChanged(int)), unlockMapper, SLOT(map()));
+ unlockMapper->setMapping(mUnlockGeneral, mGeneralCover);
+ coverLayout->addWidget(mUnlockGeneral, 5, 1, 0, 2, Qt::AlignRight);
+
+ //Connect QSignalMappers
+ connect(unlockMapper, SIGNAL(mapped(QWidget*)), this, SLOT(unlock(QWidget*)));
+ connect(browseMapper, SIGNAL(mapped(QWidget*)), this, SLOT(browse(QWidget*)));
+ connect(viewMapper, SIGNAL(mapped(QWidget*)), this, SLOT(view(QWidget*)));
+
+ //Setup Widget
+ mainLayout->addLayout(coverLayout);
+ setLayout(mainLayout);
+}
+
+void ArchiveItemCoverEdit::setCovers(const QList<QVariant> &covers){
+ QList<QVariant>::const_iterator it;
+
+ //Set front cover
+ it = std::find_if(covers.constBegin(), covers.constEnd(), std::bind2nd(CoverItem::findType(), "front"));
+ QString initialValue;
+ if(it != covers.constEnd()){
+ initialValue = it->value<CoverItem>().fileName();
+ }
+ mFrontCover->setText(initialValue);
+ mInitialValue[mFrontCover] = initialValue;
+ initialValue.clear();
+ mUnlockFront->setChecked(true);
+
+ //Set back cover
+ it = std::find_if(covers.constBegin(), covers.constEnd(), std::bind2nd(CoverItem::findType(), "back"));
+ if(it != covers.constEnd()){
+ initialValue = it->value<CoverItem>().fileName();
+ }
+ mBackCover->setText(initialValue);
+ mInitialValue[mBackCover] = initialValue;
+ initialValue.clear();
+ mUnlockBack->setChecked(true);
+
+ //Set general cover
+ it = std::find_if(covers.constBegin(), covers.constEnd(), std::bind2nd(CoverItem::findType(), "general"));
+ if(it != covers.constEnd()){
+ initialValue = it->value<CoverItem>().fileName();
+ }
+ mGeneralCover->setText(initialValue);
+ mInitialValue[mGeneralCover] = initialValue;
+ initialValue.clear();
+ mUnlockGeneral->setChecked(true);
+}
+
+QList<QVariant> ArchiveItemCoverEdit::covers() const {
+ QList<QVariant> retval;
+ QString frontCover = mFrontCover->text();
+ if(!frontCover.isEmpty()){
+ QString md5Sum = Helper::md5Sum(frontCover);
+ retval << QVariant::fromValue(CoverItem(frontCover, "front", md5Sum));
+ }
+ QString backCover = mBackCover->text();
+ if(!backCover.isEmpty()){
+ QString md5Sum = Helper::md5Sum(backCover);
+ retval << QVariant::fromValue(CoverItem(backCover, "back", md5Sum));
+ }
+ QString generalCover = mGeneralCover->text();
+ if(!generalCover.isEmpty()){
+ QString md5Sum = Helper::md5Sum(generalCover);
+ retval << QVariant::fromValue(CoverItem(generalCover, "general", md5Sum));
+ }
+ return retval;
+}
+
+void ArchiveItemCoverEdit::unlock(QWidget *lineEdit){
+ QLineEdit *editor = static_cast<QLineEdit*>(lineEdit);
+ Q_ASSERT(editor);
+ QCheckBox *checkBox = mLineEditMapping.value(editor);
+ if(!checkBox->isChecked()){
+ editor->setEnabled(true);
+ mBrowseMap.value(checkBox)->setEnabled(true);
+ checkBox->setText(mCheckboxTexts.value(checkBox).second);
+ }else{
+ editor->setText(mInitialValue.value(editor));
+ editor->setEnabled(false);
+ mBrowseMap.value(checkBox)->setEnabled(false);
+ checkBox->setText(mCheckboxTexts.value(checkBox).first);
+ }
+}
+
+void ArchiveItemCoverEdit::browse(QWidget *lineEdit){
+ QLineEdit *editor = static_cast<QLineEdit*>(lineEdit);
+ Q_ASSERT(editor);
+ if(mLastOpenedDir.isEmpty()){
+ QSettings s;
+ mLastOpenedDir = s.value("paths/selecteddir", QDir::homePath()).toString();
+ }
+ QString cover = QFileDialog::getOpenFileName(this, "Select cover", mLastOpenedDir);
+ editor->setText(cover);
+ if(!cover.isEmpty()){
+ QFileInfo fi(cover);
+ mLastOpenedDir = fi.absoluteFilePath();
+ }
+}
+
+void ArchiveItemCoverEdit::view(QWidget *lineEdit){
+ QLineEdit *editor = static_cast<QLineEdit*>(lineEdit);
+ Q_ASSERT(editor);
+ QString file = editor->text();
+ if(!file.isEmpty()){
+ mPicViewer->showPic(file, false);
+ }
+}