From eaa86b21698f516c0dd280d98aaea5414cc5611d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Tue, 22 Jan 2013 17:53:18 +0100 Subject: [PATCH] A?adida las opciones de control de imagen al di?logo de opciones, falta maquetarlo adecuadamente. --- YACReader/main_window_viewer.cpp | 1 + YACReader/options_dialog.cpp | 60 +++++++++++++++++++++++++++++++- YACReader/options_dialog.h | 10 ++++++ YACReader/render.cpp | 38 +++++++++++++------- YACReader/render.h | 1 + YACReader/viewer.cpp | 7 ++++ YACReader/viewer.h | 1 + common/yacreader_global.h | 3 ++ 8 files changed, 108 insertions(+), 13 deletions(-) diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index c4afe7e0..67e6ebbb 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -63,6 +63,7 @@ void MainWindowViewer::setupUI() connect(optionsDialog,SIGNAL(accepted()),viewer,SLOT(updateOptions())); connect(optionsDialog,SIGNAL(fitToWidthRatioChanged(float)),viewer,SLOT(updateFitToWidthRatio(float))); connect(optionsDialog, SIGNAL(optionsChanged()),this,SLOT(reloadOptions())); + connect(optionsDialog,SIGNAL(changedImageOptions()),viewer,SLOT(updateImageOptions())); optionsDialog->restoreOptions(settings); shortcutsDialog = new ShortcutsDialog(this); diff --git a/YACReader/options_dialog.cpp b/YACReader/options_dialog.cpp index 612ce881..7b67ddc8 100644 --- a/YACReader/options_dialog.cpp +++ b/YACReader/options_dialog.cpp @@ -18,8 +18,10 @@ OptionsDialog::OptionsDialog(QWidget * parent) QWidget * pageGeneral = new QWidget(); QWidget * pageFlow = new QWidget(); + QWidget * pageImage = new QWidget(); QVBoxLayout * layoutGeneral = new QVBoxLayout(); - QVBoxLayout * layoutFlow = new QVBoxLayout();; + QVBoxLayout * layoutFlow = new QVBoxLayout(); + QVBoxLayout * layoutImage = new QVBoxLayout(); QGroupBox *slideSizeBox = new QGroupBox(tr("\"Go to flow\" size")); //slideSizeLabel = new QLabel(,this); @@ -73,6 +75,31 @@ OptionsDialog::OptionsDialog(QWidget * parent) connect(selectBackgroundColorButton, SIGNAL(clicked()), colorDialog, SLOT(show())); colorBox->setLayout(colorSelection); + brightnessS = new QSlider(); + brightnessS->setMinimum(0); + brightnessS->setMaximum(100); + brightnessS->setPageStep(1); + brightnessS->setOrientation(Qt::Horizontal); + brightnessS->setTracking(false); + connect(brightnessS,SIGNAL(valueChanged(int)),this,SLOT(brightnessChanged(int))); + + contrastS = new QSlider(); + contrastS->setMinimum(0); + contrastS->setMaximum(250); + contrastS->setPageStep(1); + contrastS->setOrientation(Qt::Horizontal); + contrastS->setTracking(false); + connect(contrastS,SIGNAL(valueChanged(int)),this,SLOT(contrastChanged(int))); + + gammaS = new QSlider(); + gammaS->setMinimum(0); + gammaS->setMaximum(250); + gammaS->setPageStep(1); + gammaS->setOrientation(Qt::Horizontal); + gammaS->setTracking(false); + connect(gammaS,SIGNAL(valueChanged(int)),this,SLOT(gammaChanged(int))); + //connect(brightnessS,SIGNAL(valueChanged(int)),this,SIGNAL(changedOptions())); + QHBoxLayout * buttons = new QHBoxLayout(); buttons->addStretch(); buttons->addWidget(new QLabel(tr("Restart is needed"))); @@ -88,12 +115,18 @@ OptionsDialog::OptionsDialog(QWidget * parent) layoutFlow->addWidget(gl); layoutFlow->addWidget(useGL); layoutFlow->addStretch(); + layoutImage->addWidget(brightnessS); + layoutImage->addWidget(contrastS); + layoutImage->addWidget(gammaS); + layoutImage->addStretch(); pageGeneral->setLayout(layoutGeneral); pageFlow->setLayout(layoutFlow); + pageImage->setLayout(layoutImage); tabWidget->addTab(pageGeneral,tr("General")); tabWidget->addTab(pageFlow,tr("Page Flow")); + tabWidget->addTab(pageImage,tr("Immage adjustment")); layout->addWidget(tabWidget); layout->addLayout(buttons); @@ -165,6 +198,10 @@ void OptionsDialog::restoreOptions(QSettings * settings) updateColor(settings->value(BACKGROUND_COLOR).value()); fitToWidthRatioS->setSliderPosition(settings->value(FIT_TO_WIDTH_RATIO).toFloat()*100); + + brightnessS->setValue(settings->value(BRIGHTNESS,0).toInt()); + contrastS->setValue(settings->value(CONTRAST,100).toInt()); + gammaS->setValue(settings->value(GAMMA,100).toInt()); } @@ -185,4 +222,25 @@ void OptionsDialog::fitToWidthRatio(int value) { Configuration::getConfiguration().setFitToWidthRatio(value/100.0); emit(fitToWidthRatioChanged(value/100.0)); +} + +void OptionsDialog::brightnessChanged(int value) +{ + QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat); + settings.setValue(BRIGHTNESS,value); + emit(changedImageOptions()); +} + +void OptionsDialog::contrastChanged(int value) +{ + QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat); + settings.setValue(CONTRAST,value); + emit(changedImageOptions()); +} + +void OptionsDialog::gammaChanged(int value) +{ + QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat); + settings.setValue(GAMMA,value); + emit(changedImageOptions()); } \ No newline at end of file diff --git a/YACReader/options_dialog.h b/YACReader/options_dialog.h index a51f6018..e8a746e4 100644 --- a/YACReader/options_dialog.h +++ b/YACReader/options_dialog.h @@ -37,15 +37,25 @@ Q_OBJECT QColorDialog * colorDialog; + QSlider * brightnessS; + + QSlider * contrastS; + + QSlider * gammaS; + public slots: void saveOptions(); void restoreOptions(QSettings * settings); void findFolder(); void updateColor(const QColor & color); void fitToWidthRatio(int value); + void brightnessChanged(int value); + void contrastChanged(int value); + void gammaChanged(int value); signals: void changedOptions(); + void changedImageOptions(); void fitToWidthRatioChanged(float ratio); }; diff --git a/YACReader/render.cpp b/YACReader/render.cpp index 4e2ca521..2af7647c 100644 --- a/YACReader/render.cpp +++ b/YACReader/render.cpp @@ -10,6 +10,8 @@ #define NL 2 #define NR 2 +#include "yacreader_global.h" + template inline const T& kClamp( const T& x, const T& low, const T& high ) { @@ -238,8 +240,8 @@ QImage BrightnessFilter::setFilter(const QImage & image) } } return result;*/ - - return changeBrightness(image,50); + QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat); + return changeBrightness(image,settings.value(BRIGHTNESS,0).toInt()); } //----------------------------------------------------------------------------- @@ -309,8 +311,8 @@ QImage ContrastFilter::setFilter(const QImage & image) } return result;*/ - - return changeContrast(image,level); + QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat); + return changeContrast(image,settings.value(CONTRAST,100).toInt()); } //----------------------------------------------------------------------------- // ContrastFilter @@ -322,7 +324,8 @@ GammaFilter::GammaFilter(int l) QImage GammaFilter::setFilter(const QImage & image) { - return changeGamma(image,level); + QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat); + return changeGamma(image,settings.value(GAMMA,100).toInt()); } //----------------------------------------------------------------------------- @@ -438,7 +441,9 @@ Render::Render() pageRenders.push_back(0); } - //filters.push_back(new GammaFilter(250)); + filters.push_back(new BrightnessFilter()); + filters.push_back(new ContrastFilter()); + filters.push_back(new GammaFilter()); } //Este método se encarga de forzar el renderizado de las páginas. @@ -822,7 +827,7 @@ void Render::fillBuffer() pageRenders[currentPageBufferedIndex+i]==0 && pagesReady[currentIndex+1]) //preload next pages { - pageRenders[currentPageBufferedIndex+i] = new PageRender(currentIndex+i,comic->getRawData()->at(currentIndex+i),buffer[currentPageBufferedIndex+i],imageRotation); + pageRenders[currentPageBufferedIndex+i] = new PageRender(currentIndex+i,comic->getRawData()->at(currentIndex+i),buffer[currentPageBufferedIndex+i],imageRotation,filters); connect(pageRenders[currentPageBufferedIndex],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); pageRenders[currentPageBufferedIndex+i]->start(); } @@ -833,7 +838,7 @@ void Render::fillBuffer() pageRenders[currentPageBufferedIndex-i]==0 && pagesReady[currentIndex-1]) //preload previous pages { - pageRenders[currentPageBufferedIndex-i] = new PageRender(currentIndex-i,comic->getRawData()->at(currentIndex-i),buffer[currentPageBufferedIndex-i],imageRotation); + pageRenders[currentPageBufferedIndex-i] = new PageRender(currentIndex-i,comic->getRawData()->at(currentIndex-i),buffer[currentPageBufferedIndex-i],imageRotation,filters); connect(pageRenders[currentPageBufferedIndex],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); pageRenders[currentPageBufferedIndex-i]->start(); } @@ -851,9 +856,9 @@ void Render::fillBufferDoublePage() (pagesReady[currentIndex+2*i] && pagesReady[qMin(currentIndex+(2*i)+1,(int)comic->numPages()-1)])) //preload next pages { if(currentIndex+(2*i)+1 > comic->numPages()-1) - pageRenders[currentPageBufferedIndex+i] = new DoublePageRender(currentIndex+2*i,comic->getRawData()->at(currentIndex+(2*i)),QByteArray(),buffer[currentPageBufferedIndex+i],imageRotation); + pageRenders[currentPageBufferedIndex+i] = new DoublePageRender(currentIndex+2*i,comic->getRawData()->at(currentIndex+(2*i)),QByteArray(),buffer[currentPageBufferedIndex+i],imageRotation,filters); else - pageRenders[currentPageBufferedIndex+i] = new DoublePageRender(currentIndex+2*i,comic->getRawData()->at(currentIndex+(2*i)),comic->getRawData()->at(currentIndex+(2*i)+1),buffer[currentPageBufferedIndex+i],imageRotation); + pageRenders[currentPageBufferedIndex+i] = new DoublePageRender(currentIndex+2*i,comic->getRawData()->at(currentIndex+(2*i)),comic->getRawData()->at(currentIndex+(2*i)+1),buffer[currentPageBufferedIndex+i],imageRotation,filters); connect(pageRenders[currentPageBufferedIndex],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); pageRenders[currentPageBufferedIndex+i]->start(); } @@ -865,9 +870,9 @@ void Render::fillBufferDoublePage() (pagesReady[qMax(currentIndex-2*i,0)] && pagesReady[qMin(currentIndex-(2*i)+1,(int)comic->numPages()-1)])) //preload previous pages { if(currentIndex-2*i == -1) - pageRenders[currentPageBufferedIndex-i] = new DoublePageRender(0,QByteArray(),comic->getRawData()->at(0),buffer[currentPageBufferedIndex-i],imageRotation); + pageRenders[currentPageBufferedIndex-i] = new DoublePageRender(0,QByteArray(),comic->getRawData()->at(0),buffer[currentPageBufferedIndex-i],imageRotation,filters); else - pageRenders[currentPageBufferedIndex-i] = new DoublePageRender(currentIndex-2*i,comic->getRawData()->at(currentIndex-(2*i)),comic->getRawData()->at(currentIndex-(2*i)+1),buffer[currentPageBufferedIndex-i],imageRotation); + pageRenders[currentPageBufferedIndex-i] = new DoublePageRender(currentIndex-2*i,comic->getRawData()->at(currentIndex-(2*i)),comic->getRawData()->at(currentIndex-(2*i)+1),buffer[currentPageBufferedIndex-i],imageRotation,filters); connect(pageRenders[currentPageBufferedIndex],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); pageRenders[currentPageBufferedIndex-i]->start(); } @@ -932,4 +937,13 @@ void Render::save() Bookmarks * Render::getBookmarks() { return comic->bm; +} + +void Render::reload() +{ + if(comic) + { + invalidate(); + update(); + } } \ No newline at end of file diff --git a/YACReader/render.h b/YACReader/render.h index cab7d1eb..7d50502f 100644 --- a/YACReader/render.h +++ b/YACReader/render.h @@ -147,6 +147,7 @@ public slots: void removeBookmark(); void save(); void reset(); + void reload(); Bookmarks * getBookmarks(); signals: diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index 34df22b9..2cd10b8a 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -736,6 +736,13 @@ void Viewer::updateConfig(QSettings * settings) QPalette palette; palette.setColor(backgroundRole(), Configuration::getConfiguration().getBackgroundColor()); setPalette(palette); + + +} + +void Viewer::updateImageOptions() +{ + render->reload(); } void Viewer::setBookmarks() diff --git a/YACReader/viewer.h b/YACReader/viewer.h index 91d30203..00246e62 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -77,6 +77,7 @@ virtual void mouseReleaseEvent ( QMouseEvent * event ); void updateConfig(QSettings * settings); void showMessageErrorOpening(); void setBookmarks(); + void updateImageOptions(); private: bool information; diff --git a/common/yacreader_global.h b/common/yacreader_global.h index b643a427..164dca31 100644 --- a/common/yacreader_global.h +++ b/common/yacreader_global.h @@ -21,6 +21,9 @@ #define BACKGROUND_COLOR "BACKGROUND_COLOR" #define ALWAYS_ON_TOP "ALWAYS_ON_TOP" #define SHOW_TOOLBARS "SHOW_TOOLBARS" +#define BRIGHTNESS "BRIGHTNESS" +#define CONTRAST "CONTRAST" +#define GAMMA "GAMMA" #define FLOW_TYPE_GL "FLOW_TYPE_GL" #define Y_POSITION "Y_POSITION"