diff --git a/Viewer/ImageDisplay.cpp b/Viewer/ImageDisplay.cpp index ea7787f..c07e724 100644 --- a/Viewer/ImageDisplay.cpp +++ b/Viewer/ImageDisplay.cpp @@ -330,6 +330,32 @@ void Viewer::ImageDisplay::cropAndScale() update(); } +void Viewer::ImageDisplay::filterNone() +{ + cropAndScale(); + update(); +} + +void Viewer::ImageDisplay::filterMono() +{ + _croppedAndScaledImg = _croppedAndScaledImg.convertToFormat(_croppedAndScaledImg.Format_Mono); + update(); +} + +// I can't believe there isn't a standard conversion for this??? -- WH +void Viewer::ImageDisplay::filterBW() +{ + for (int y = 0; y < _croppedAndScaledImg.height(); ++y) { + for (int x = 0; x < _croppedAndScaledImg.width(); ++x) { + int pixel = _croppedAndScaledImg.pixel(x, y); + int gray = qGray(pixel); + int alpha = qAlpha(pixel); + _croppedAndScaledImg.setPixel(x, y, qRgba(gray, gray, gray, alpha)); + } + } + update(); +} + void Viewer::ImageDisplay::updateZoomCaption() { const QSize imgSize = _loadedImage.size(); // similar to sizeRatio(), but we take the _highest_ factor. diff --git a/Viewer/ImageDisplay.h b/Viewer/ImageDisplay.h index e54938a..0ca6a5a 100644 --- a/Viewer/ImageDisplay.h +++ b/Viewer/ImageDisplay.h @@ -59,6 +59,10 @@ public: virtual void pixmapLoaded( const QString& fileName, const QSize& size, const QSize& fullSize, int angle, const QImage&, const bool loadedOK); void setImageList( const QStringList& list ); + void filterNone(); + void filterMono(); + void filterBW(); + public slots: void zoomIn(); void zoomOut(); diff --git a/Viewer/ViewerWidget.cpp b/Viewer/ViewerWidget.cpp index 9ea3625..095afa1 100644 --- a/Viewer/ViewerWidget.cpp +++ b/Viewer/ViewerWidget.cpp @@ -136,6 +136,7 @@ void Viewer::ViewerWidget::setupContextMenu() createInvokeExternalMenu(); createVideoMenu(); createCategoryImageMenu(); + createFilterMenu(); KAction* action = _actions->addAction( QString::fromLatin1("viewer-edit-image-properties"), this, SLOT( editImage() ) ); action->setText( i18n("Annotate...") ); @@ -414,6 +415,7 @@ void Viewer::ViewerWidget::load() _rotateMenu->setEnabled( !isVideo ); _wallpaperMenu->setEnabled( !isVideo ); _categoryImagePopup->setEnabled( !isVideo ); + _filterMenu->setEnabled( !isVideo ); #ifdef HAVE_EXIV2 _showExifViewer->setEnabled( !isVideo ); #endif @@ -835,6 +837,27 @@ void Viewer::ViewerWidget::editImage() MainWindow::Window::configureImages( list, true ); } +void Viewer::ViewerWidget::filterNone() +{ + if ( _display == _imageDisplay ) { + _imageDisplay->filterNone(); + } +} + +void Viewer::ViewerWidget::filterBW() +{ + if ( _display == _imageDisplay ) { + _imageDisplay->filterBW(); + } +} + +void Viewer::ViewerWidget::filterMono() +{ + if ( _display == _imageDisplay ) { + _imageDisplay->filterMono(); + } +} + void Viewer::ViewerWidget::slotSetStackHead() { MainWindow::Window::theMainWindow()->setStackHead( DB::ImageDB::instance()->ID_FOR_FILE( _list[ _current ] ) ); @@ -1050,6 +1073,27 @@ void Viewer::ViewerWidget::createCategoryImageMenu() connect( _categoryImagePopup, SIGNAL( aboutToShow() ), this, SLOT( populateCategoryImagePopup() ) ); } +void Viewer::ViewerWidget::createFilterMenu() +{ + _filterMenu = new QMenu( _popup ); + _filterMenu->setTitle( i18n("Filters") ); + + _filterNone = _actions->addAction( QString::fromLatin1("filter-empty"), this, SLOT( filterNone() ) ); + _filterNone->setText( i18n("Remove All Filters") ); + _filterMenu->addAction( _filterNone ); + + _filterBW = _actions->addAction( QString::fromLatin1("filter-bw"), this, SLOT( filterBW() ) ); + _filterBW->setText( i18n("Apply Grayscale Filter") ); + _filterMenu->addAction( _filterBW ); + + _filterMono = _actions->addAction( QString::fromLatin1("filter-mono"), this, SLOT( filterMono() ) ); + _filterMono->setText( i18n("Apply Monochrome Filter") ); + _filterMenu->addAction( _filterMono ); + + _popup->addMenu( _filterMenu ); +} + + void Viewer::ViewerWidget::test() { #ifdef TESTING diff --git a/Viewer/ViewerWidget.h b/Viewer/ViewerWidget.h index fe123cc..bb1a434 100644 --- a/Viewer/ViewerWidget.h +++ b/Viewer/ViewerWidget.h @@ -90,6 +90,7 @@ protected: void createSlideShowMenu(); void createVideoMenu(); void createCategoryImageMenu(); + void createFilterMenu(); void changeSlideShowInterval( int delta ); void createVideoViewer(); @@ -122,6 +123,9 @@ protected slots: void slotSlideShowFaster(); void slotSlideShowSlower(); void editImage(); + void filterNone(); + void filterBW(); + void filterMono(); void slotSetStackHead(); void updateCategoryConfig(); void slotSetWallpaperC(); @@ -153,6 +157,9 @@ private: KAction* _slideShowRunFaster; KAction* _slideShowRunSlower; KAction* _setStackHead; + KAction* _filterNone; + KAction* _filterBW; + KAction* _filterMono; Display* _display; ImageDisplay* _imageDisplay; @@ -165,6 +172,7 @@ private: QMenu* _popup; QMenu* _rotateMenu; QMenu* _wallpaperMenu; + QMenu* _filterMenu; MainWindow::ExternalPopup* _externalPopup; MainWindow::CategoryImagePopup* _categoryImagePopup; int _width, _height;