From 95179c2db141de61e4c199cfb377fb9542bdb24b Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Mon, 18 Mar 2019 17:08:38 +0100 Subject: [PATCH] filter panel added --- cfilterpanel.cpp | 14 ++ cfilterpanel.h | 22 ++++ cfilterpanel.ui | 70 ++++++++++ cmainwindow.cpp | 10 +- cmainwindow.h | 3 + cmainwindow.ui | 313 +++++++++++++++++++++++---------------------- cspoiler.cpp | 80 ++++++++++++ cspoiler.h | 70 ++++++++++ pictureLibrary.pro | 11 +- 9 files changed, 439 insertions(+), 154 deletions(-) create mode 100644 cfilterpanel.cpp create mode 100644 cfilterpanel.h create mode 100644 cfilterpanel.ui create mode 100644 cspoiler.cpp create mode 100644 cspoiler.h diff --git a/cfilterpanel.cpp b/cfilterpanel.cpp new file mode 100644 index 0000000..693c5be --- /dev/null +++ b/cfilterpanel.cpp @@ -0,0 +1,14 @@ +#include "cfilterpanel.h" +#include "ui_cfilterpanel.h" + +cFilterPanel::cFilterPanel(QWidget *parent) : + QWidget(parent), + ui(new Ui::cFilterPanel) +{ + ui->setupUi(this); +} + +cFilterPanel::~cFilterPanel() +{ + delete ui; +} diff --git a/cfilterpanel.h b/cfilterpanel.h new file mode 100644 index 0000000..7db6533 --- /dev/null +++ b/cfilterpanel.h @@ -0,0 +1,22 @@ +#ifndef CFILTERPANEL_H +#define CFILTERPANEL_H + +#include + +namespace Ui { +class cFilterPanel; +} + +class cFilterPanel : public QWidget +{ + Q_OBJECT + +public: + explicit cFilterPanel(QWidget *parent = nullptr); + ~cFilterPanel(); + +private: + Ui::cFilterPanel *ui; +}; + +#endif // CFILTERPANEL_H diff --git a/cfilterpanel.ui b/cfilterpanel.ui new file mode 100644 index 0000000..41aaf31 --- /dev/null +++ b/cfilterpanel.ui @@ -0,0 +1,70 @@ + + + cFilterPanel + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + Person + + + true + + + + + + + + + + + + Location + + + true + + + + + + + + + + + + Tags + + + true + + + + + + + + + + + + + + + diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 2258b37..b3c77e3 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -13,7 +13,6 @@ #include "ccombopicker.h" #include "cimage.h" - #include "cimageviewer.h" #include "ui_cmainwindow.h" @@ -31,11 +30,13 @@ #include #include #include +#include cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) : QMainWindow(parent), ui(new Ui::cMainWindow), + m_lpFilterPanel(nullptr), m_lpProgressBar(nullptr), m_lpFolderViewModel(nullptr), m_lpFolderSortFilterProxyModel(nullptr), @@ -61,6 +62,9 @@ cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) : cMainWindow::~cMainWindow() { + if(m_lpFilterPanel) + delete m_lpFilterPanel; + delete m_lpThumbnailViewModel; delete m_lpFolderViewModel; delete m_lpThumbnailSortFilterProxyModel; @@ -75,6 +79,10 @@ void cMainWindow::initUI() QIcon::setThemeName("TangoMFK"); + ui->m_lpSpoiler->setTitle(tr("Filter")); + m_lpFilterPanel = new cFilterPanel(this); + ui->m_lpSpoiler->setContentWidget(m_lpFilterPanel); + m_lpFolderViewModel = new QStandardItemModel; m_lpFolderSortFilterProxyModel = new cFolderSortFilterProxyModel(this); ui->m_lpFolderView->setModel(m_lpFolderSortFilterProxyModel); diff --git a/cmainwindow.h b/cmainwindow.h index 2ab1084..0f4b0b1 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -19,6 +19,8 @@ #include "ctoolboxinfo.h" +#include "cfilterpanel.h" + #include #include @@ -64,6 +66,7 @@ public: private: Ui::cMainWindow* ui; /*!< TODO: describe */ + cFilterPanel* m_lpFilterPanel; /*!< TODO: describe */ QProgressBar* m_lpProgressBar; /*!< TODO: describe */ QStandardItemModel* m_lpFolderViewModel; /*!< TODO: describe */ cFolderSortFilterProxyModel* m_lpFolderSortFilterProxyModel; /*!< TODO: describe */ diff --git a/cmainwindow.ui b/cmainwindow.ui index 906f60c..312f526 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -15,158 +15,165 @@ - - - - Qt::Horizontal - - - - - 0 - 0 - - - - - 10 - 0 - - - - - 0 - 0 - - - - Qt::CustomContextMenu - - - QAbstractItemView::NoEditTriggers - - - true - - - true - - - - - - 1 - 0 - - - - Qt::CustomContextMenu - - - QAbstractItemView::NoEditTriggers - - - QAbstractItemView::ExtendedSelection - - - - 160 - 120 - - - - QListView::Adjust - - - - 180 - 180 - - - - QListView::IconMode - - - true - - - - - true - - - - - 0 - 0 - 87 - 609 - + + + + + + Qt::Horizontal - - - - - 3 - - - - - 0 - 0 - 69 - 483 - - - - Information - - - - - - 0 - 0 - 69 - 483 - - - - Person - - - - - - 0 - 0 - 69 - 483 - - - - Location - - - - - - 0 - 0 - 69 - 483 - - - - Tags - - - - - + + + + 0 + 0 + + + + + 10 + 0 + + + + + 0 + 0 + + + + Qt::CustomContextMenu + + + QAbstractItemView::NoEditTriggers + + + true + + + true + + + + + + 1 + 0 + + + + Qt::CustomContextMenu + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::ExtendedSelection + + + + 160 + 120 + + + + QListView::Adjust + + + + 180 + 180 + + + + QListView::IconMode + + + true + + + + + true + + + + + 0 + 0 + 87 + 591 + + + + + + + 3 + + + + + 0 + 0 + 69 + 465 + + + + Information + + + + + + 0 + 0 + 69 + 465 + + + + Person + + + + + + 0 + 0 + 69 + 465 + + + + Location + + + + + + 0 + 0 + 69 + 465 + + + + Tags + + + + + + + - - + + + + + @@ -221,6 +228,12 @@
ctoolboxtag.h
1 + + cSpoiler + QWidget +
cspoiler.h
+ 1 +
diff --git a/cspoiler.cpp b/cspoiler.cpp new file mode 100644 index 0000000..4804a42 --- /dev/null +++ b/cspoiler.cpp @@ -0,0 +1,80 @@ +/*! + \file cspoiler.cpp + +*/ + +#include "cspoiler.h" + +#include + + +cSpoiler::cSpoiler(QWidget *parent) : + QWidget(parent), + m_animationDuration(300) +{ + m_toggleButton.setStyleSheet("QToolButton { border: none; }"); + m_toggleButton.setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + m_toggleButton.setArrowType(Qt::ArrowType::RightArrow); + m_toggleButton.setText(""); + m_toggleButton.setCheckable(true); + m_toggleButton.setChecked(false); + + m_headerLine.setFrameShape(QFrame::HLine); + m_headerLine.setFrameShadow(QFrame::Sunken); + m_headerLine.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); + + m_contentArea.setStyleSheet("QScrollArea { border: none; }"); + m_contentArea.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + // start out collapsed + m_contentArea.setMaximumHeight(0); + m_contentArea.setMinimumHeight(0); + // let the entire widget grow and shrink with its content + m_toggleAnimation.addAnimation(new QPropertyAnimation(this, "minimumHeight")); + m_toggleAnimation.addAnimation(new QPropertyAnimation(this, "maximumHeight")); + m_toggleAnimation.addAnimation(new QPropertyAnimation(&m_contentArea, "maximumHeight")); + // don't waste space + m_mainLayout.setVerticalSpacing(0); + m_mainLayout.setContentsMargins(0, 0, 0, 0); + int row = 0; + m_mainLayout.addWidget(&m_toggleButton, row, 0, 1, 1, Qt::AlignLeft); + m_mainLayout.addWidget(&m_headerLine, row++, 2, 1, 1); + m_mainLayout.addWidget(&m_contentArea, row, 0, 1, 3); + setLayout(&m_mainLayout); + QObject::connect(&m_toggleButton, &QToolButton::clicked, [this](const bool checked) + { + m_toggleButton.setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow); + m_toggleAnimation.setDirection(checked ? QAbstractAnimation::Forward : QAbstractAnimation::Backward); + m_toggleAnimation.start(); + }); +} + +void cSpoiler::setTitle(const QString& title) +{ + m_toggleButton.setText(title); +} + +void cSpoiler::setContentLayout(QLayout& contentLayout) +{ + delete m_contentArea.layout(); + m_contentArea.setLayout(&contentLayout); + const auto collapsedHeight = sizeHint().height() - m_contentArea.maximumHeight(); + auto contentHeight = contentLayout.sizeHint().height(); + for (int i = 0; i < m_toggleAnimation.animationCount() - 1; ++i) + { + QPropertyAnimation * spoilerAnimation = static_cast(m_toggleAnimation.animationAt(i)); + spoilerAnimation->setDuration(m_animationDuration); + spoilerAnimation->setStartValue(collapsedHeight); + spoilerAnimation->setEndValue(collapsedHeight + contentHeight); + } + QPropertyAnimation * contentAnimation = static_cast(m_toggleAnimation.animationAt(m_toggleAnimation.animationCount() - 1)); + contentAnimation->setDuration(m_animationDuration); + contentAnimation->setStartValue(0); + contentAnimation->setEndValue(contentHeight); +} + +void cSpoiler::setContentWidget(QWidget* contentWidget) +{ + auto* lpLayout = new QVBoxLayout(); + lpLayout->addWidget(contentWidget); + setContentLayout(*lpLayout); +} diff --git a/cspoiler.h b/cspoiler.h new file mode 100644 index 0000000..24e7c41 --- /dev/null +++ b/cspoiler.h @@ -0,0 +1,70 @@ +/*! + \file cspoiler.h + +*/ + +#ifndef CSPOILER_H +#define CSPOILER_H + + +#include +#include +#include +#include +#include +#include + + +/*! + \brief + + \class cSpoiler cspoiler.h "cspoiler.h" +*/ +class cSpoiler : public QWidget +{ + Q_OBJECT +public: + /*! + \brief + + \fn cSpoiler + \param parent + */ + explicit cSpoiler(QWidget *parent = nullptr); + + /*! + \brief + + \fn setTitle + \param title + */ + void setTitle(const QString& title); + /*! + \brief + + \fn setContentLayout + \param contentLayout + */ + void setContentLayout(QLayout& contentLayout); + /*! + \brief + + \fn setContentWidget + \param contentWidget + */ + void setContentWidget(QWidget* contentWidget); + +signals: + +public slots: + +private: + QGridLayout m_mainLayout; /*!< TODO: describe */ + QToolButton m_toggleButton; /*!< TODO: describe */ + QFrame m_headerLine; /*!< TODO: describe */ + QParallelAnimationGroup m_toggleAnimation; /*!< TODO: describe */ + QScrollArea m_contentArea; /*!< TODO: describe */ + int m_animationDuration{300}; /*!< TODO: describe */ +}; + +#endif // CSPOILER_H diff --git a/pictureLibrary.pro b/pictureLibrary.pro index 927c15b..c4aa2b4 100644 --- a/pictureLibrary.pro +++ b/pictureLibrary.pro @@ -76,7 +76,9 @@ SOURCES += \ ctag.cpp \ clocation.cpp \ ctoolboxlocation.cpp \ - ctoolboxtag.cpp + ctoolboxtag.cpp \ + cspoiler.cpp \ + cfilterpanel.cpp HEADERS += \ cmainwindow.h \ @@ -101,7 +103,9 @@ HEADERS += \ ctag.h \ clocation.h \ ctoolboxlocation.h \ - ctoolboxtag.h + ctoolboxtag.h \ + cspoiler.h \ + cfilterpanel.h FORMS += \ cmainwindow.ui \ @@ -113,7 +117,8 @@ FORMS += \ ctoolboxperson.ui \ cimageviewer.ui \ ctoolboxlocation.ui \ - ctoolboxtag.ui + ctoolboxtag.ui \ + cfilterpanel.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin