From da19e086db229919a154cbcbf9dd7d4024fe4677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 7 Dec 2015 22:48:13 +0100 Subject: [PATCH] added settings to the options dialog for configuring the background image in grid view --- YACReaderLibrary/grid_comics_view.cpp | 55 ++++++++-------- YACReaderLibrary/grid_comics_view.h | 1 + YACReaderLibrary/library_window.cpp | 4 +- YACReaderLibrary/options_dialog.cpp | 90 +++++++++++++++++++++++---- YACReaderLibrary/options_dialog.h | 14 +++++ 5 files changed, 125 insertions(+), 39 deletions(-) diff --git a/YACReaderLibrary/grid_comics_view.cpp b/YACReaderLibrary/grid_comics_view.cpp index 4b02b2e1..770921a7 100644 --- a/YACReaderLibrary/grid_comics_view.cpp +++ b/YACReaderLibrary/grid_comics_view.cpp @@ -160,28 +160,40 @@ void GridComicsView::setModel(ComicModel *model) ctxt->setContextProperty("dragManager", this); ctxt->setContextProperty("dropManager", this); + updateBackgroundConfig(); - //backgroun image configuration - bool useBackgroundImage = settings->value(USE_BACKGROUND_IMAGE_IN_GRID_VIEW, true).toBool(); + if(model->rowCount()>0) + setCurrentIndex(model->index(0,0)); + } +} - if(useBackgroundImage) - { - float opacity = settings->value(OPACITY_BACKGROUND_IMAGE_IN_GRID_VIEW, 0.2).toFloat(); - float blurRadius = settings->value(BLUR_RADIUS_BACKGROUND_IMAGE_IN_GRID_VIEW, 75).toFloat(); +void GridComicsView::updateBackgroundConfig() +{ + if(this->model == NULL) + return; - ctxt->setContextProperty("backgroundImage", this->model->data(this->model->index(0, 0), ComicModel::CoverPathRole)); - ctxt->setContextProperty("backgroundBlurOpacity", opacity); - ctxt->setContextProperty("backgroundBlurRadius", blurRadius); - ctxt->setContextProperty("backgroundBlurVisible", true); - } - else - { - ctxt->setContextProperty("backgroundImage", QVariant()); - ctxt->setContextProperty("backgroundBlurOpacity", 0); - ctxt->setContextProperty("backgroundBlurRadius", 0); - ctxt->setContextProperty("backgroundBlurVisible", false); - } + QQmlContext *ctxt = view->rootContext(); + //backgroun image configuration + bool useBackgroundImage = settings->value(USE_BACKGROUND_IMAGE_IN_GRID_VIEW, true).toBool(); + + if(useBackgroundImage) + { + float opacity = settings->value(OPACITY_BACKGROUND_IMAGE_IN_GRID_VIEW, 0.2).toFloat(); + float blurRadius = settings->value(BLUR_RADIUS_BACKGROUND_IMAGE_IN_GRID_VIEW, 75).toInt(); + + ctxt->setContextProperty("backgroundImage", this->model->data(this->model->index(0, 0), ComicModel::CoverPathRole)); + ctxt->setContextProperty("backgroundBlurOpacity", opacity); + ctxt->setContextProperty("backgroundBlurRadius", blurRadius); + ctxt->setContextProperty("backgroundBlurVisible", true); + } + else + { + ctxt->setContextProperty("backgroundImage", QVariant()); + ctxt->setContextProperty("backgroundBlurOpacity", 0); + ctxt->setContextProperty("backgroundBlurRadius", 0); + ctxt->setContextProperty("backgroundBlurVisible", false); + } #ifdef Q_OS_MAC ctxt->setContextProperty("cellColor", useBackgroundImage?"#99FFFFFF":"#FFFFFF"); @@ -190,13 +202,6 @@ void GridComicsView::setModel(ComicModel *model) ctxt->setContextProperty("cellColor", useBackgroundImage?"#99212121":"#212121"); ctxt->setContextProperty("selectedColor", "#121212"); #endif - - if(model->rowCount()>0) - setCurrentIndex(model->index(0,0)); - } - - - } void GridComicsView::setCurrentIndex(const QModelIndex &index) diff --git a/YACReaderLibrary/grid_comics_view.h b/YACReaderLibrary/grid_comics_view.h index da8a894c..8a876198 100644 --- a/YACReaderLibrary/grid_comics_view.h +++ b/YACReaderLibrary/grid_comics_view.h @@ -63,6 +63,7 @@ public slots: void droppedFiles(const QList & urls, Qt::DropAction action); void droppedComicsForResortingAt(const QString & data, int index); + void updateBackgroundConfig(); protected slots: void requestedContextMenu(const QPoint & point); diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index ed13b638..e95ffc39 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -135,9 +135,9 @@ void LibraryWindow::setupUI() createActions(); doModels(); + doDialogs(); doLayout(); createToolBars(); - doDialogs(); createMenus(); navigationController = new YACReaderNavigationController(this); @@ -245,6 +245,7 @@ void LibraryWindow::doLayout() //comicsViewStack->setCurrentIndex(Flow); } else { comicsView = gridComicsView = new GridComicsView(); + connect(optionsDialog, SIGNAL(optionsChanged()), gridComicsView, SLOT(updateBackgroundConfig())); comicsViewStatus = Grid; //comicsViewStack->setCurrentIndex(Grid); } @@ -2256,6 +2257,7 @@ void LibraryWindow::toggleComicsView_delayed() libraryToolBar->updateViewSelectorIcon(icoViewsButton); #endif switchToComicsView(classicComicsView, gridComicsView = new GridComicsView()); + connect(optionsDialog, SIGNAL(optionsChanged()), gridComicsView, SLOT(updateBackgroundConfig())); comicsViewStatus = Grid; } else{ diff --git a/YACReaderLibrary/options_dialog.cpp b/YACReaderLibrary/options_dialog.cpp index 6073347f..bfd81eff 100644 --- a/YACReaderLibrary/options_dialog.cpp +++ b/YACReaderLibrary/options_dialog.cpp @@ -7,18 +7,6 @@ #include "yacreader_flow_config_widget.h" #include "api_key_dialog.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - FlowType flowType = Strip; @@ -30,6 +18,7 @@ OptionsDialog::OptionsDialog(QWidget * parent) QVBoxLayout * layout = new QVBoxLayout(this); QVBoxLayout * flowLayout = new QVBoxLayout; + QVBoxLayout * gridViewLayout = new QVBoxLayout(); QVBoxLayout * generalLayout = new QVBoxLayout(); QHBoxLayout * switchFlowType = new QHBoxLayout(); @@ -61,9 +50,43 @@ OptionsDialog::OptionsDialog(QWidget * parent) connect(apiKeyButton,SIGNAL(clicked()),this,SLOT(editApiKey())); + //grid view background config + useBackgroundImageCheck = new QCheckBox(tr("Enable background image")); + + opacityLabel = new QLabel(tr("Opacity level")); + + backgroundImageOpacitySlider = new QSlider(Qt::Horizontal); + backgroundImageOpacitySlider->setRange(5,100); + + blurLabel = new QLabel(tr("Opacity level")); + + backgroundImageBlurRadiusSlider = new QSlider(Qt::Horizontal); + backgroundImageBlurRadiusSlider->setRange(0,100); + + QVBoxLayout * gridBackgroundLayout = new QVBoxLayout(); + gridBackgroundLayout->addWidget(useBackgroundImageCheck); + gridBackgroundLayout->addWidget(opacityLabel); + gridBackgroundLayout->addWidget(backgroundImageOpacitySlider); + gridBackgroundLayout->addWidget(blurLabel); + gridBackgroundLayout->addWidget(backgroundImageBlurRadiusSlider); + + QGroupBox * gridBackgroundGroup = new QGroupBox(tr("Background")); + gridBackgroundGroup->setLayout(gridBackgroundLayout); + + gridViewLayout->addWidget(gridBackgroundGroup); + gridViewLayout->addStretch(); + + connect(useBackgroundImageCheck, SIGNAL(clicked(bool)), this, SLOT(useBackgroundImageCheckClicked(bool))); + connect(backgroundImageOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(backgroundImageOpacitySliderChanged(int))); + connect(backgroundImageBlurRadiusSlider, SIGNAL(valueChanged(int)), this, SLOT(backgroundImageBlurRadiusSliderChanged(int))); + //end grid view background config + QWidget * comicFlowW = new QWidget; comicFlowW->setLayout(flowLayout); + QWidget * gridViewW = new QWidget; + gridViewW->setLayout(gridViewLayout); + QWidget * generalW = new QWidget; generalW->setLayout(generalLayout); generalLayout->addWidget(shortcutsBox); @@ -71,6 +94,9 @@ OptionsDialog::OptionsDialog(QWidget * parent) generalLayout->addStretch(); tabWidget->addTab(comicFlowW,tr("Comic Flow")); +#ifndef NO_OPENGL + tabWidget->addTab(gridViewW,tr("Grid view")); +#endif tabWidget->addTab(generalW,tr("General")); layout->addWidget(tabWidget); @@ -82,7 +108,6 @@ OptionsDialog::OptionsDialog(QWidget * parent) setWindowTitle(tr("Options")); this->layout()->setSizeConstraint(QLayout::SetFixedSize); - } void OptionsDialog::editApiKey() @@ -91,5 +116,44 @@ void OptionsDialog::editApiKey() d.exec(); } +void OptionsDialog::restoreOptions(QSettings * settings) +{ + YACReaderOptionsDialog::restoreOptions(settings); + bool useBackgroundImage = settings->value(USE_BACKGROUND_IMAGE_IN_GRID_VIEW, true).toBool(); + useBackgroundImageCheck->setChecked(useBackgroundImage); + backgroundImageOpacitySlider->setValue(settings->value(OPACITY_BACKGROUND_IMAGE_IN_GRID_VIEW, 0.2).toFloat()*100); + backgroundImageBlurRadiusSlider->setValue(settings->value(BLUR_RADIUS_BACKGROUND_IMAGE_IN_GRID_VIEW, 75).toInt()); + + backgroundImageOpacitySlider->setVisible(useBackgroundImage); + backgroundImageBlurRadiusSlider->setVisible(useBackgroundImage); + opacityLabel->setVisible(useBackgroundImage); + blurLabel->setVisible(useBackgroundImage); +} + +void OptionsDialog::useBackgroundImageCheckClicked(bool checked) +{ + settings->setValue(USE_BACKGROUND_IMAGE_IN_GRID_VIEW, checked); + + backgroundImageOpacitySlider->setVisible(checked); + backgroundImageBlurRadiusSlider->setVisible(checked); + opacityLabel->setVisible(checked); + blurLabel->setVisible(checked); + + emit optionsChanged(); +} + +void OptionsDialog::backgroundImageOpacitySliderChanged(int value) +{ + settings->setValue(OPACITY_BACKGROUND_IMAGE_IN_GRID_VIEW, value/100.0); + + emit optionsChanged(); +} + +void OptionsDialog::backgroundImageBlurRadiusSliderChanged(int value) +{ + settings->setValue(BLUR_RADIUS_BACKGROUND_IMAGE_IN_GRID_VIEW, value); + + emit optionsChanged(); +} diff --git a/YACReaderLibrary/options_dialog.h b/YACReaderLibrary/options_dialog.h index 9a2ca1bc..4b40e4c4 100644 --- a/YACReaderLibrary/options_dialog.h +++ b/YACReaderLibrary/options_dialog.h @@ -1,6 +1,8 @@ #ifndef __OPTIONS_DIALOG_H #define __OPTIONS_DIALOG_H +#include + #include "yacreader_options_dialog.h" #include "yacreader_global.h" @@ -15,6 +17,18 @@ Q_OBJECT public slots: void editApiKey(); + void restoreOptions(QSettings * settings); + + private slots: + void useBackgroundImageCheckClicked(bool checked); + void backgroundImageOpacitySliderChanged(int value); + void backgroundImageBlurRadiusSliderChanged(int value); + private: + QCheckBox * useBackgroundImageCheck; + QSlider * backgroundImageOpacitySlider; + QSlider * backgroundImageBlurRadiusSlider; + QLabel * opacityLabel; + QLabel * blurLabel; };