diff --git a/CMakeLists.txt b/CMakeLists.txt index ebbe146..f16f701 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,52 +1,69 @@ project(kmag) -find_package(KDE4 REQUIRED) -include (KDE4Defaults) -include (MacroLibrary) +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +set(QT_MIN_VERSION "5.2.0") -macro_optional_find_package(QAccessibilityClient) -macro_log_feature(QAccessibilityClient_FOUND "qaccessibilityclient" "KDE client-side accessibility library" "https://projects.kde.org/projects/playground/accessibility/libkdeaccessibilityclient" FALSE "" "Required to enable keyboard focus tracking.") +find_package(ECM 1.3.0 REQUIRED NO_MODULE) +set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) + +add_definitions(-DTRANSLATION_DOMAIN="kmag") + +include(KDEInstallDirs) +include(KDECompilerSettings) +include(KDECMakeSettings) +include(FeatureSummary) + +find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS + Core + Widgets +) + +find_package(KF5 REQUIRED COMPONENTS + KDELibs4Support +) + +#macro_optional_find_package(QAccessibilityClient) +#macro_log_feature(QAccessibilityClient_FOUND "qaccessibilityclient" "KDE client-side accessibility library" "https://projects.kde.org/projects/playground/accessibility/libkdeaccessibilityclient" FALSE "" "Required to enable keyboard focus tracking.") configure_file( "${PROJECT_SOURCE_DIR}/focustrackconfig.h.in" "${PROJECT_BINARY_DIR}/focustrackconfig.h") -add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) add_definitions( -DQT_NO_CAST_FROM_ASCII ) add_definitions( -DQT_NO_CAST_TO_ASCII ) add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES}) if(QAccessibilityClient_FOUND) include_directories(${QACCESSIBILITYCLIENT_INCLUDE_DIR}) endif(QAccessibilityClient_FOUND) add_subdirectory( doc ) add_subdirectory( pics ) ########### next target ############### set(kmag_SRCS kmagzoomview.cpp kmagselrect.cpp kmag.cpp colorsim.cpp main.cpp ) -kde4_add_executable(kmag ${kmag_SRCS}) +add_executable(kmag ${kmag_SRCS}) -target_link_libraries(kmag ${KDE4_KIO_LIBS}) +target_link_libraries(kmag Qt5::Core Qt5::Widgets KF5::KDELibs4Support) if(QAccessibilityClient_FOUND) target_link_libraries(kmag ${QACCESSIBILITYCLIENT_LIBRARY}) endif(QAccessibilityClient_FOUND) install(TARGETS kmag ${INSTALL_TARGETS_DEFAULT_ARGS} ) -macro_display_feature_log() +feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) ########### install files ############### install( PROGRAMS kmag.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} ) -install( FILES kmagui.rc DESTINATION ${DATA_INSTALL_DIR}/kmag ) +install( FILES kmagui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/kmag ) kde4_install_icons( ${ICON_INSTALL_DIR} ) diff --git a/colorsim.cpp b/colorsim.cpp index c550483..d5935d9 100644 --- a/colorsim.cpp +++ b/colorsim.cpp @@ -1,314 +1,314 @@ /*************************************************************************** colorsim.cpp - description ------------------- begin : Mon Jan 21 14:54:37 CST 2008 copyright : (C) 2008 by Matthew Woehlke email : mw_triad@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ /*************************************************************************** Citations: [1] H. Brettel, F. Viénot and J. D. Mollon (1997) "Computerized simulation of color appearance for dichromats." J. Opt. Soc. Am. A 14, 2647-2655. [2] F. Viénot, H. Brettel and J. D. Mollon (1999) "Digital video colourmaps for checking the legibility of displays by dichromats." Color Research and Application 24, 243-252. ***************************************************************************/ // application specific includes #include "colorsim.h" // include files for Qt -#include +#include #include typedef qreal matrix[3][3]; #define SIMPLE_ALGORITHM #ifndef SIMPLE_ALGORITHM typedef qreal vector[3]; struct fcoef { vector k[2]; // vector e; matrix s[2]; }; #endif class xyza { private: qreal x, y, z, a; public: xyza() {} xyza(const QColor &c); QRgb rgba() const; xyza gamma(qreal q) const; xyza operator*(const matrix m) const; #ifndef SIMPLE_ALGORITHM xyza(const vector v); qreal operator*(const vector m) const; xyza flatten(fcoef c) const; #endif }; xyza::xyza(const QColor &c) : x(c.redF()), y(c.greenF()), z(c.blueF()), a(c.alphaF()) { } inline qreal clamp(qreal n) { return qMin(qreal(1.0), qMax(qreal(0.0), n)); } QRgb xyza::rgba() const { return QColor::fromRgbF(clamp(x), clamp(y), clamp(z), a).rgba(); } xyza xyza::operator*(const matrix m) const { xyza r; r.x = (x * m[0][0]) + (y * m[0][1]) + (z * m[0][2]); r.y = (x * m[1][0]) + (y * m[1][1]) + (z * m[1][2]); r.z = (x * m[2][0]) + (y * m[2][1]) + (z * m[2][2]); r.a = a; return r; } xyza xyza::gamma(qreal q) const { xyza r; r.x = pow(x, q); r.y = pow(y, q); r.z = pow(z, q); r.a = a; return r; } #if !defined(SIMPLE_ALGORITHM) || !defined(STANFORD_ALGORITHM) /*************************************************************************** These RGB<->LMS transformation matrices are from [1]. ***************************************************************************/ static const matrix rgb2lms = { {0.1992, 0.4112, 0.0742}, {0.0353, 0.2226, 0.0574}, {0.0185, 0.1231, 1.3550} }; static const matrix lms2rgb = { { 7.4645, -13.8882, 0.1796}, {-1.1852, 6.8053, -0.2234}, { 0.0058, -0.4286, 0.7558} }; #endif #ifdef SIMPLE_ALGORITHM # ifndef STANFORD_ALGORITHM // from "Computerized simulation of color appearance for dichromats" # ifdef CRA_ALGORITHM /*************************************************************************** These matrices are derived from Table II in [2], for the code based on the Onur/Poliang algorithm below, using the LMS transformation from [1]. No tritanopia data were provided, so that simulation does not work correctly. ***************************************************************************/ static const matrix coef[3] = { { {0.0, 2.39238646, -0.04658523}, {0.0, 1.0, 0.0 }, {0.0, 0.0, 1.0} }, { {1.0, 0.0, 0.0 }, {0.41799267, 0.0, 0.01947228}, {0.0, 0.0, 1.0} }, { {1.0, 0.0, 0.0 }, {0.0, 1.0, 0.0 }, {0.0, 0.0, 0.0} } }; # else /*************************************************************************** These matrices are derived from the "Color Blindness Simulation" sample palettes from Visolve, Ryobi System Solutions, using the LMS transformations from [1]. http://www.ryobi-sol.co.jp/visolve/en/simulation.html ***************************************************************************/ static const matrix coef[3] = { { {0.0, 2.60493696, -0.08742194}, {0.0, 1.0, 0.0 }, {0.0, 0.0, 1.0} }, { {1.0, 0.0, 0.0 }, {0.38395980, 0.0, 0.03370622}, {0.0, 0.0, 1.0} }, { {1.0, 0.0, 0.0 }, {0.0, 1.0, 0.0 }, {-3.11932916, 12.18076308, 0.0} } }; # endif # else // from the "Analysis of Color Blindness" project /*************************************************************************** This code is based on the matrices from [2], as presented by Onur and Poliang. The tritanopia simulation uses different representative wavelengths (yellow and blue) than those reccommended by [1] and found in most other simulations (red and cyan). http://www.stanford.edu/~ofidaner/psych221_proj/colorblindness_project.htm ***************************************************************************/ static const matrix coef[3] = { { { 0.0, 2.02344, -2.52581}, {0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0} }, { { 1.0, 0.0, 0.0 }, {0.494207, 0.0, 1.24827}, { 0.0, 0.0, 1.0} }, { { 1.0, 0.0, 0.0 }, {0.0, 1.0, 0.0 }, {-0.395913, 0.801109, 0.0} } }; static const matrix rgb2lms = { {17.8824, 43.5161, 4.11935}, { 3.45565, 27.1554, 3.86714}, { 0.0299566, 0.184309, 1.46709} }; static const matrix lms2rgb = { { 0.080944447905, -0.130504409160, 0.116721066440}, {-0.010248533515, 0.054019326636, -0.113614708214}, {-0.000365296938, -0.004121614686, 0.693511404861} }; # endif inline QRgb recolor(QRgb c, int mode, qreal g) { if (mode > 0 && mode < 4) { xyza n = QColor(c); if (g != 1.0) { xyza r = n.gamma(g) * rgb2lms * coef[mode-1] * lms2rgb; return r.gamma(qreal(1.0) / g).rgba(); } else { xyza r = n * rgb2lms * coef[mode-1] * lms2rgb; return r.rgba(); } } else { return qRgb(qGray(c), qGray(c), qGray(c)); } } #else // from "Computerized simulation of color appearance for dichromats" /*************************************************************************** This code is based on [1]. The RGB<->LMS transformation matrices are declared above. ***************************************************************************/ static const fcoef coef[3] = { { { {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0} }, // k // { }, // e // a { } { // s { {0.0, 2.39238646, -0.04658523}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0} }, { {0.0, 0.37421464, -0.02034378}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0} } } }, { { {0.0, 0.0, 1.0}, {1.0, 0.0, 0.0} }, // k // { }, // e // a { } { // s { {1.0, 0.0, 0.0}, {0.41799267, 0.0, 0.01947228}, {0.0, 0.0, 1.0} }, { {1.0, 0.0, 0.0}, {0.41799267, 0.0, 0.01947228}, {0.0, 0.0, 1.0} } } }, { { {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0} }, // k // { }, // e // a { } { // s { {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 0.0} }, { {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 0.0} } } } /* The 's' matrices are calculated thusly: u = E.y*A.z - E.z*A.y; v = E.z*A.x - E.x*A.z; w = E.x*A.y - E.y*A.x; r.x = (mode != 1) ? x : (-v/u) * y + (-w/u) * z; r.y = (mode != 2) ? y : (-u/v) * x + (-w/v) * z; r.z = (mode != 3) ? z : (-u/w) * x + (-v/w) * y; */ }; xyza::xyza(const vector v) : x(v[0]), y(v[1]), z(v[2]), a(0.0) { } qreal xyza::operator*(const vector v) const { return (x * v[0]) + (y * v[1]) + (z * v[2]); } xyza xyza::flatten(fcoef c) const { // xyza e(c.e); // qreal u = (*this * c.k[0]) / (*this * c.k[1]); // qreal v = (e * c.k[0]) / (e * c.k[1]); // int i = (u < v ? 0 : 1); int i = 0; return *this * c.s[i]; } inline QRgb recolor(QRgb c, int mode, qreal g) { if (mode > 0 && mode < 4) { xyza n = QColor(c); xyza r = n.gamma(g) * rgb2lms; r = r.flatten(coef[mode-1]) * lms2rgb; return r.gamma(qreal(1.0) / g).rgba(); } else { const int g = qGray(c); return qRgb(g,g,g); } } #endif QImage ColorSim::recolor(const QImage &pm, int mode, qreal gamma) { // get raw data in a format we can manipulate QImage i = pm; if (i.format() != QImage::Format_RGB32 && i.format() != QImage::Format_ARGB32) i = i.convertToFormat(QImage::Format_ARGB32); int n = i.width() * i.height(); QRgb *d = (QRgb*)i.bits(); for (int k = 0; k < n; ++k) d[k] = ::recolor(d[k], mode, gamma); return i; } // kate: indent-width 2; diff --git a/colorsim.h b/colorsim.h index 23d2f9c..75c4ed0 100644 --- a/colorsim.h +++ b/colorsim.h @@ -1,35 +1,35 @@ /*************************************************************************** colorsim.h - description ------------------- begin : Mon Jan 21 14:54:37 CST 2008 copyright : (C) 2008 by Matthew Woehlke email : mw_triad@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef KMAGCOLORSIM_H #define KMAGCOLORSIM_H // include files for Qt -#include -#include +#include +#include namespace ColorSim { /** * Recolor a pixmap according to the specified simulation mode: * 1 - Protanopia * 2 - Deuteranopia * 3 - Tritanopia * 4 - Achromatopsia */ QImage recolor(const QImage &pm, int mode, qreal gamma = 1.0); } #endif diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index c19af9f..408411a 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -1,5 +1,5 @@ ########### install files ############### # -kde4_create_handbook(index.docbook INSTALL_DESTINATION ${HTML_INSTALL_DIR}/en SUBDIR kmag) -kde4_create_manpage(man-kmag.1.docbook 1 INSTALL_DESTINATION ${MAN_INSTALL_DIR}) +kdoctools_create_handbook(index.docbook INSTALL_DESTINATION ${HTML_INSTALL_DIR}/en SUBDIR kmag) +kdoctools_create_manpage(man-kmag.1.docbook 1 INSTALL_DESTINATION ${MAN_INSTALL_DIR}) diff --git a/kmag.cpp b/kmag.cpp index dd2331f..71530e3 100644 --- a/kmag.cpp +++ b/kmag.cpp @@ -1,861 +1,862 @@ /*************************************************************************** kmag.cpp - description ------------------- begin : Mon Feb 12 23:45:41 EST 2001 copyright : (C) 2001-2003 by Sarang Lakare email : sarang#users.sourceforge.net copyright : (C) 2003-2004 by Olaf Schmidt email : ojschmidt@kde.org copyright : (C) 2008 by Matthew Woehlke email : mw_triad@users.sourceforge.net copyright (C) 2010 Sebastian Sauer email sebsauer@kdab.com ***************************************************************************/ /*************************************************************************** * * * 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 files for QT -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // include files for KDE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include +#include #include #include #include #include #include #include #include #include #include #include #include // application specific includes -#include "kmag.moc" +#include "kmag.h" #include "kmagzoomview.h" #include "kmagselrect.h" KmagApp::KmagApp(QWidget* , const char* name) : KXmlGuiWindow(0) // Qt::WStyle_MinMax | Qt::WType_TopLevel | Qt::WDestructiveClose | Qt::WStyle_ContextHelp | Qt::WindowCloseButtonHint | Qt::WStyle_StaysOnTop , m_defaultMouseCursorType(2) { setObjectName( QLatin1String( name ) ); setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); config=KGlobal::config(); zoomArrayString << QLatin1String( "5:1" ) << QLatin1String( "2:1" ) << QLatin1String( "1:1" ) << QLatin1String( "1:1.5" ) << QLatin1String( "1:2" ) << QLatin1String( "1:3" ) << QLatin1String( "1:4" ) << QLatin1String( "1:5" ) << QLatin1String( "1:6" ) << QLatin1String( "1:7" ) << QLatin1String( "1:8" ) << QLatin1String( "1:12" ) << QLatin1String( "1:16" ) << QLatin1String( "1:20" ); zoomArray << 0.2 <<0.5 << 1.0; zoomArray << 1.5 << 2.0 << 3.0; zoomArray << 4.0 << 5.0 << 6.0 << 7.0; zoomArray << 8.0 << 12.0 << 16.0 << 20.0; fpsArrayString << i18nc("Zoom at very low", "&Very Low") << i18nc("Zoom at low", "&Low") << i18nc("Zoom at medium", "&Medium") << i18nc("Zoom at high", "&High") << i18nc("Zoom at very high", "V&ery High"); fpsArray.append(2); // very low fpsArray.append(6); // low fpsArray.append(10); // medium fpsArray.append(15); // high fpsArray.append(25); // very high colorArrayString << i18nc("No color-blindness simulation, i.e. 'normal' vision", "&Normal") << i18n("&Protanopia") << i18n("&Deuteranopia") << i18n("&Tritanopia") << i18n("&Achromatopsia"); colorArray.append(0); colorArray.append(1); colorArray.append(2); colorArray.append(3); colorArray.append(4); rotationArrayString << i18n("&No Rotation (0 Degrees)") << i18n("&Left (90 Degrees)") << i18n("&Upside Down (180 Degrees)") << i18n("&Right (270 Degrees)"); rotationArray.append(0); // no rotation rotationArray.append(90); // left rotationArray.append(180); // upside down rotationArray.append(270); // right // call inits to invoke all other construction parts initView(); initActions(); initConnections(); // read options from config file readOptions(); #ifndef QT_NO_PRINTER m_printer = 0; #endif // QT_NO_PRINTER } /** * Default destructor. */ KmagApp::~KmagApp() { m_zoomView->showSelRect(false); #ifndef QT_NO_PRINTER delete m_printer; #endif // QT_NO_PRINTER } void KmagApp::initActions() { fileNewWindow = actionCollection()->addAction(QLatin1String( "new_window" )); fileNewWindow->setIcon(KIcon(QLatin1String( "window-new" ))); fileNewWindow->setText(i18n("New &Window")); connect(fileNewWindow, SIGNAL(triggered(bool)), SLOT(slotFileNewWindow())); fileNewWindow->setShortcuts(KStandardShortcut::openNew()); fileNewWindow->setToolTip(i18n("Open a new KMagnifier window")); refreshSwitch = actionCollection()->addAction(QLatin1String( "start_stop_refresh" )); refreshSwitch->setIcon(KIcon(QLatin1String( "process-stop" ))); refreshSwitch->setText(i18n("&Stop")); connect(refreshSwitch, SIGNAL(triggered(bool)), SLOT(slotToggleRefresh())); refreshSwitch->setShortcuts(KStandardShortcut::reload()); refreshSwitch->setToolTip(i18n("Click to stop window refresh")); refreshSwitch->setWhatsThis(i18n("Clicking on this icon will start / stop " "updating of the display. Stopping the update will zero the processing power " "required (CPU usage)")); m_pSnapshot = actionCollection()->addAction(QLatin1String( "snapshot" )); m_pSnapshot->setIcon(KIcon(QLatin1String( "ksnapshot" ))); m_pSnapshot->setText(i18n("&Save Snapshot As...")); connect(m_pSnapshot, SIGNAL(triggered(bool)), SLOT(saveZoomPixmap())); m_pSnapshot->setShortcuts(KStandardShortcut::save()); m_pSnapshot->setWhatsThis(i18n("Saves the zoomed view to an image file.")); m_pSnapshot->setToolTip(i18n("Save image to a file")); m_pPrint = actionCollection()->addAction(KStandardAction::Print, this, SLOT(slotFilePrint())); m_pPrint->setWhatsThis(i18n("Click on this button to print the current zoomed view.")); m_pQuit = actionCollection()->addAction(KStandardAction::Quit, this, SLOT(slotFileQuit())); m_pQuit->setToolTip(i18n("Quits the application")); m_pQuit->setWhatsThis (i18n("Quits the application")); m_pCopy = actionCollection()->addAction(KStandardAction::Copy, this, SLOT(copyToClipBoard())); m_pCopy->setWhatsThis(i18n("Click on this button to copy the current zoomed view to the clipboard which you can paste in other applications.")); m_pCopy->setToolTip(i18n("Copy zoomed image to clipboard")); m_pShowMenu = KStandardAction::showMenubar(this, SLOT(slotShowMenu()), actionCollection()); setStandardToolBarMenuEnabled(true); m_modeFollowMouse = new KToggleAction(KIcon(QLatin1String( "followmouse" )), i18n("&Follow Mouse Mode"), this); actionCollection()->addAction(QLatin1String( "mode_followmouse" ), m_modeFollowMouse); connect(m_modeFollowMouse, SIGNAL(triggered(bool)), SLOT(slotModeChanged())); m_modeFollowMouse->setShortcut(Qt::Key_F2); m_modeFollowMouse->setIconText(i18n("Mouse")); m_modeFollowMouse->setToolTip(i18n("Magnify around the mouse cursor")); m_modeFollowMouse->setWhatsThis(i18n("If selected, the area around the mouse cursor is magnified")); #ifdef QAccessibilityClient_FOUND m_modeFollowFocus = new KToggleAction(KIcon(QLatin1String( "view-restore" )), i18n("&Follow Focus Mode"), this); actionCollection()->addAction(QLatin1String( "mode_followfocus" ), m_modeFollowFocus); connect(m_modeFollowFocus, SIGNAL(triggered(bool)), SLOT(slotModeChanged())); m_modeFollowFocus->setShortcut(Qt::Key_F2); m_modeFollowFocus->setIconText(i18n("Focus")); m_modeFollowFocus->setToolTip(i18n("Magnify around the keyboard focus")); m_modeFollowFocus->setWhatsThis(i18n("If selected, the area around the keyboard cursor is magnified")); #endif m_modeSelWin = new KToggleAction(KIcon(QLatin1String( "window" )), i18n("Se&lection Window Mode"), this); actionCollection()->addAction(QLatin1String( "mode_selectionwindow" ), m_modeSelWin); connect(m_modeSelWin, SIGNAL(triggered(bool)), SLOT(slotModeSelWin())); m_modeSelWin->setShortcut(Qt::Key_F3); m_modeSelWin->setIconText(i18n("Window")); m_modeSelWin->setToolTip(i18n("Show a window for selecting the magnified area")); m_modeWholeScreen = new KToggleAction(KIcon(QLatin1String( "view-fullscreen" )), i18n("&Whole Screen Mode"), this); actionCollection()->addAction(QLatin1String( "mode_wholescreen" ), m_modeWholeScreen); connect(m_modeWholeScreen, SIGNAL(triggered(bool)), SLOT(slotModeWholeScreen())); m_modeWholeScreen->setShortcut(Qt::Key_F4); m_modeWholeScreen->setIconText(i18n("Screen")); m_modeWholeScreen->setToolTip(i18n("Magnify the whole screen")); m_modeWholeScreen->setWhatsThis(i18n("Click on this button to fit the zoom view to the zoom window.")); m_hideCursor = new KToggleAction(KIcon(QLatin1String( "hidemouse" )), i18n("Hide Mouse &Cursor"), this); actionCollection()->addAction(QLatin1String( "hidecursor" ), m_hideCursor); connect(m_hideCursor, SIGNAL(triggered(bool)), SLOT(slotToggleHideCursor())); m_hideCursor->setShortcut(Qt::Key_F6); #ifdef havesetCheckedStatef m_hideCursor->setCheckedState(KGuiItem(i18n("Show Mouse &Cursor"))); #endif m_hideCursor->setIconText(i18n("Hide")); m_hideCursor->setToolTip(i18n("Hide the mouse cursor")); m_staysOnTop = new KToggleAction(KIcon(QLatin1String( "go-top" )), i18n("Stays On Top"), this); actionCollection()->addAction(QLatin1String( "staysontop" ), m_staysOnTop); connect(m_staysOnTop, SIGNAL(triggered(bool)), SLOT(slotStaysOnTop())); m_staysOnTop->setShortcut(Qt::Key_F7); m_staysOnTop->setToolTip(i18n("The KMagnifier Window stays on top of other windows.")); m_pZoomIn = actionCollection()->addAction(KStandardAction::ZoomIn, this, SLOT(zoomIn())); m_pZoomIn->setWhatsThis(i18n("Click on this button to zoom-in on the selected region.")); m_pZoomBox = new KSelectAction(i18n("&Zoom"), this); actionCollection()->addAction(QLatin1String( "zoom" ), m_pZoomBox); m_pZoomBox->setItems(zoomArrayString); m_pZoomBox->setWhatsThis(i18n("Select the zoom factor.")); m_pZoomBox->setToolTip(i18n("Zoom factor")); m_pZoomOut = actionCollection()->addAction(KStandardAction::ZoomOut, this, SLOT(zoomOut())); m_pZoomOut->setWhatsThis(i18n("Click on this button to zoom-out on the selected region.")); m_pRotationBox = new KSelectAction(i18n("&Rotation"),this); actionCollection()->addAction(QLatin1String( "rotation" ), m_pRotationBox); m_pRotationBox->setItems(rotationArrayString); m_pRotationBox->setWhatsThis(i18n("Select the rotation degree.")); m_pRotationBox->setToolTip(i18n("Rotation degree")); // KHelpMenu *newHelpMenu = new KHelpMenu(this, KGlobal::mainComponent().aboutData()); m_keyConf = actionCollection()->addAction(KStandardAction::KeyBindings, this, SLOT(slotConfKeys())); m_toolConf = actionCollection()->addAction(KStandardAction::ConfigureToolbars, this, SLOT(slotEditToolbars())); m_pFPSBox = new KSelectAction(i18n("&Refresh"),this); actionCollection()->addAction(QLatin1String( "fps_selector" ), m_pFPSBox); m_pFPSBox->setItems(fpsArrayString); m_pFPSBox->setWhatsThis(i18n("Select the refresh rate. The higher the rate, the more computing power (CPU) will be needed.")); m_pFPSBox->setToolTip(i18n("Refresh rate")); m_pColorBox = new KSelectAction(i18nc("Color-blindness simulation mode", "&Color"),this); actionCollection()->addAction(QLatin1String( "color_mode" ), m_pColorBox); m_pColorBox->setItems(colorArrayString); m_pColorBox->setWhatsThis(i18n("Select a mode to simulate various types of color-blindness.")); m_pColorBox->setToolTip(i18n("Color-blindness Simulation Mode")); setupGUI(ToolBar | Keys | Save | Create); } void KmagApp::initView() { m_zoomView = new KMagZoomView( this, "ZoomView" ); //m_zoomView->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, m_zoomView->sizePolicy().hasHeightForWidth() ) ); m_zoomView->setFrameShape( QFrame::NoFrame ); setCentralWidget(m_zoomView); } void KmagApp::slotChangeZoomBoxIndex(int index) { m_pZoomBox->setCurrentItem(index); } void KmagApp::slotChangeRotationBoxIndex(int index) { m_pRotationBox->setCurrentItem(index); } void KmagApp::slotChangeFPSIndex(int index) { m_pFPSBox->setCurrentItem(index); } void KmagApp::slotChangeColorIndex(int index) { m_pColorBox->setCurrentItem(index); } /** * Initialize all connections. */ void KmagApp::initConnections() { // change in zoom value -> update the view connect(this, SIGNAL(updateZoomValue(float)), m_zoomView, SLOT(setZoom(float))); connect(this, SIGNAL(updateRotationValue(int)), m_zoomView, SLOT(setRotation(int))); connect(this, SIGNAL(updateFPSValue(float)), m_zoomView, SLOT(setRefreshRate(float))); connect(this, SIGNAL(updateColorValue(int)), m_zoomView, SLOT(setColorMode(int))); // change in zoom index -> update the selector connect(this, SIGNAL(updateZoomIndex(int)), this, SLOT(slotChangeZoomBoxIndex(int))); connect(this, SIGNAL(updateRotationIndex(int)), this, SLOT(slotChangeRotationBoxIndex(int))); connect(this, SIGNAL(updateFPSIndex(int)), this, SLOT(slotChangeFPSIndex(int))); connect(this, SIGNAL(updateColorIndex(int)), this, SLOT(slotChangeColorIndex(int))); // selector selects a zoom index -> set the zoom index connect(m_pZoomBox, SIGNAL(triggered(int)), this, SLOT(setZoomIndex(int))); connect(m_pRotationBox, SIGNAL(triggered(int)), this, SLOT(setRotationIndex(int))); connect(m_pFPSBox, SIGNAL(triggered(int)), this, SLOT(setFPSIndex(int))); connect(m_pColorBox, SIGNAL(triggered(int)), this, SLOT(setColorIndex(int))); } /** * Save options to config file. */ void KmagApp::saveOptions() { KConfigGroup cg( config, "General Options"); cg.writeEntry("Geometry", size()); cg.writeEntry("ZoomIndex", m_zoomIndex); cg.writeEntry("RotationIndex", m_rotationIndex); cg.writeEntry("FPSIndex", m_fpsIndex); cg.writeEntry("ColorIndex", m_colorIndex); cg.writeEntry("SelRect", m_zoomView->getSelRectPos()); cg.writeEntry("ShowMouse", m_zoomView->getShowMouseType()); cg.writeEntry("StaysOnTop", m_staysOnTop->isChecked()); if (m_modeFollowMouse->isChecked()) cg.writeEntry("Mode", "followmouse"); #ifdef QAccessibilityClient_FOUND else if (m_modeFollowFocus->isChecked()) cg.writeEntry("Mode", "followfocus"); #endif else if (m_modeWholeScreen->isChecked()) cg.writeEntry("Mode", "wholescreen"); else if (m_modeSelWin->isChecked()) cg.writeEntry("Mode", "selectionwindow"); } /** * Read settings from config file. */ void KmagApp::readOptions() { QColor blue (0,0,128); QColor yellow (255,255,0); QColor white (255,255,255); KConfigGroup cgWM( config, "WM"); setTitleColors ( cgWM.readEntry("inactiveBackground", blue), cgWM.readEntry("inactiveForeground", white), cgWM.readEntry("inactiveTitleBtnBg", yellow)); KConfigGroup cg(config,"General Options"); QSize defSize(460,390); QSize size=cg.readEntry("Geometry", defSize); if(!size.isEmpty()) { resize(size); } // set zoom - defaults to 2x unsigned int zoomIndex = cg.readEntry("ZoomIndex", 4); setZoomIndex(zoomIndex); emit updateZoomIndex(m_zoomIndex); unsigned int rotationIndex = cg.readEntry("RotationIndex", 0); setRotationIndex(rotationIndex); emit updateRotationIndex(m_rotationIndex); unsigned int fpsIndex = cg.readEntry("FPSIndex", 2); setFPSIndex(fpsIndex); emit updateFPSIndex(m_fpsIndex); unsigned int colorIndex = cg.readEntry("ColorIndex", 0); setColorIndex(colorIndex); emit updateColorIndex(colorIndex); /* QString mode = cg.readEntry("Mode", "followmouse"); if (mode == QLatin1String( "wholescreen" )) { slotModeWholeScreen(); } else if (mode == QLatin1String( "selectionwindow" )) { slotModeSelWin(); } else if (mode == QLatin1String( "followfocus" )) { m_modeFollowFocus->setChecked(true); slotModeChanged(); } else { m_modeFollowMouse->setChecked(true); slotModeChanged(); } */ QRect defaultRect(0,0,211,164); m_zoomView->setSelRectPos(cg.readEntry("SelRect", defaultRect)); m_mouseCursorType = cg.readEntry("ShowMouse", m_defaultMouseCursorType); m_zoomView->showMouse(m_mouseCursorType); m_hideCursor->setChecked(!m_mouseCursorType); m_staysOnTop->setChecked(cg.readEntry("StaysOnTop", true)); slotStaysOnTop(); // XMLGui has already read and set up the menuBar for us m_pShowMenu->setChecked(menuBar()->isVisible()); } bool KmagApp::queryClose() { saveOptions(); return (true); } /** * Called when mouse is clicked inside the window * * @param e */ void KmagApp::contextMenuEvent ( QContextMenuEvent * e ) { // show popup KXMLGUIFactory *factory = this->factory(); QMenu *popup = (QMenu *)factory->container(QLatin1String( "mainPopUp" ),this); if (popup != 0) popup->popup(e->globalPos()); e->accept(); } ///////////////////////////////////////////////////////////////////// // SLOT IMPLEMENTATION ///////////////////////////////////////////////////////////////////// /** * Shows/hides the mouse cursor */ void KmagApp::showMouseCursor(bool show) { if(show) { if(m_mouseCursorType == 0) m_mouseCursorType = m_defaultMouseCursorType; m_zoomView->showMouse(m_mouseCursorType); } else { m_zoomView->showMouse(0); } } /** * Zoom in. */ void KmagApp::zoomIn() { // set the new index .. checking will done inside setZoom setZoomIndex(m_zoomIndex+1); // signal change in zoom index emit updateZoomIndex((int)m_zoomIndex); } /** * Zoom out. */ void KmagApp::zoomOut() { // set the new index .. checking will done inside setZoom setZoomIndex(m_zoomIndex-1); // signal change in zoom index emit updateZoomIndex((int)m_zoomIndex); } /** * Sets the zoom index to index */ void KmagApp::setZoomIndex(int index) { if(index < 0 || index >= (int)zoomArray.size()) { // the index is invalid kWarning() << "Invalid index!" ; return; } else if((int)m_zoomIndex == index) { // do nothing! return; } else { m_zoomIndex = index; } if(m_zoomIndex == 0) { // meaning that no more zooming-out is possible // -> disable zoom-out icon m_pZoomOut->setEnabled(false); } else { // enable the icon m_pZoomOut->setEnabled(true); } if(m_zoomIndex == zoomArray.size()-1) { // meaning that no more zooming-in is possible // -> disable zoom-in icon m_pZoomIn->setEnabled(false); } else { // enable the icon m_pZoomIn->setEnabled(true); } // signal change in zoom value emit updateZoomValue(zoomArray.at(m_zoomIndex)); } /** * Sets the rotation index to index */ void KmagApp::setRotationIndex(int index) { if(index < 0 || index >= (int)rotationArray.size()) { // the index is invalid kWarning() << "Invalid index!" ; return; } else if((int)m_rotationIndex == index) { // do nothing! return; } else { m_rotationIndex = index; } // signal change in zoom value emit updateRotationValue(rotationArray.at(m_rotationIndex)); } /** * Sets the fps index to index */ void KmagApp::setFPSIndex(int index) { if(index < 0 || index >= (int)fpsArray.size()) { // the index is invalid kWarning() << "Invalid index!" ; return; } else if((int)m_fpsIndex == index) { // do nothing! return; } else { m_fpsIndex = index; } // signal change in fps value emit updateFPSValue(fpsArray.at(m_fpsIndex)); } /** * Sets the color index to index */ void KmagApp::setColorIndex(int index) { if(index < 0 || index >= (int)colorArray.size()) { // the index is invalid kWarning() << "Invalid index!" ; return; } else if((int)m_colorIndex == index) { // do nothing! return; } else { m_colorIndex = index; } // signal change in fps value emit updateColorValue(colorArray.at(m_colorIndex)); } /** * Save the zoomed image */ void KmagApp::saveZoomPixmap() { bool toggled(false); // stop refresh temporarily if (m_zoomView->getRefreshStatus()) { slotToggleRefresh(); toggled = true; } - KUrl url = KFileDialog::getSaveUrl(QString(), + QUrl url = KFileDialog::getSaveUrl(QString(), KImageIO::pattern(KImageIO::Writing), 0,i18n("Save Snapshot As")); if(!url.fileName().isEmpty()) { if(!url.isLocalFile()) { // create a temp file.. save image to it.. copy over the n/w and then delete the temp file. KTemporaryFile tempFile; #ifdef __GNUC__ #warning "kde4: port KImageIO::type \n"; #endif if(!tempFile.open() || !m_zoomView->getImage().save(tempFile.fileName(),"png"/*, KImageIO::type(url.fileName()).latin1()*/)) { KMessageBox::error(0, i18n("Unable to save temporary file (before uploading to the network file you specified)."), i18n("Error Writing File")); } else { if(!KIO::NetAccess::upload(tempFile.fileName(), url, this)) { KMessageBox::error(0, i18n("Unable to upload file over the network."), i18n("Error Writing File")); } else { - KMessageBox::information(0, i18n("Current zoomed image saved to\n%1", url.prettyUrl()), + KMessageBox::information(0, i18n("Current zoomed image saved to\n%1", url.toDisplayString()), i18n("Information"), QLatin1String( "save_confirm" )); } } } else { #ifdef __GNUC__ #warning "kde4 : port KImageIO::type(...) \n"; #endif if(!m_zoomView->getImage().save(url.path(), "png"/*KImageIO::type(url.fileName()).latin1()*/)) { KMessageBox::error(0, i18n("Unable to save file. Please check if you have permission to write to the directory."), i18n("Error Writing File")); } else { - KMessageBox::information(0, i18n("Current zoomed image saved to\n%1", url.prettyUrl()), + KMessageBox::information(0, i18n("Current zoomed image saved to\n%1", url.toDisplayString()), i18n("Information"), QLatin1String( "save_confirm" )); } } } if(toggled) { slotToggleRefresh(); } } void KmagApp::slotToggleRefresh() { m_zoomView->toggleRefresh(); if(m_zoomView->getRefreshStatus()) { refreshSwitch->setIcon(KIcon(QLatin1String( "process-stop" ))); refreshSwitch->setText(i18n("Stop")); refreshSwitch->setToolTip(i18n("Click to stop window update")); } else { refreshSwitch->setIcon(KIcon(QLatin1String( "system-run" ))); refreshSwitch->setText(i18nc("Start updating the window", "Start")); refreshSwitch->setToolTip(i18n("Click to start window update")); } } void KmagApp::slotModeWholeScreen() { m_zoomView->followMouse(false); m_zoomView->setSelRectPos(QRect (0, 0, QApplication::desktop()->width(), QApplication::desktop()->height())); m_zoomView->showSelRect(false); m_zoomView->setFitToWindow (false); m_modeFollowMouse->setChecked(false); #ifdef QAccessibilityClient_FOUND m_zoomView->followBoth(false); m_zoomView->followFocus(false); m_modeFollowFocus->setChecked(false); #endif m_modeWholeScreen->setChecked(true); m_modeSelWin->setChecked(false); } void KmagApp::slotModeSelWin() { m_zoomView->followMouse(false); m_zoomView->showSelRect(true); m_zoomView->setFitToWindow (false); m_modeFollowMouse->setChecked(false); #ifdef QAccessibilityClient_FOUND m_zoomView->followBoth(false); m_zoomView->followFocus(false); m_modeFollowFocus->setChecked(false); #endif m_modeWholeScreen->setChecked(false); m_modeSelWin->setChecked(true); } void KmagApp::slotModeChanged() { #ifdef QAccessibilityClient_FOUND if(m_modeFollowMouse->isChecked() && m_modeFollowFocus->isChecked()) { //BOTH MODE m_zoomView->followMouse(false); m_zoomView->followBoth(true); m_zoomView->followFocus(false); m_zoomView->showSelRect(false); m_zoomView->setFitToWindow (true); m_modeWholeScreen->setChecked(false); m_modeSelWin->setChecked(false); return; } #endif if (m_modeFollowMouse->isChecked()) { //MOUSE MODE m_zoomView->followMouse(true); m_zoomView->showSelRect(false); m_zoomView->setFitToWindow (true); m_modeFollowMouse->setChecked(true); #ifdef QAccessibilityClient_FOUND m_zoomView->followBoth(false); m_zoomView->followFocus(false); m_modeFollowFocus->setChecked(false); #endif m_modeWholeScreen->setChecked(false); m_modeSelWin->setChecked(false); #ifdef QAccessibilityClient_FOUND } else if (m_modeFollowFocus->isChecked()) { //FOCUS MODE m_zoomView->followBoth(false); m_zoomView->followMouse(false); m_zoomView->followFocus(true); m_zoomView->showSelRect(false); m_zoomView->setFitToWindow (true); m_modeFollowMouse->setChecked(false); m_modeFollowFocus->setChecked(true); m_modeWholeScreen->setChecked(false); m_modeSelWin->setChecked(false); #endif } } void KmagApp::slotToggleHideCursor() { showMouseCursor(!m_hideCursor->isChecked()); } void KmagApp::slotStaysOnTop() { if (m_staysOnTop->isChecked()) setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint ); else setWindowFlags( windowFlags() & !Qt::WindowStaysOnTopHint ); show(); } void KmagApp::slotFileNewWindow() { KmagApp *new_window= new KmagApp(); new_window->show(); } void KmagApp::slotFilePrint() { #ifndef QT_NO_PRINTER bool toggled(false); if (m_printer == 0) { m_printer = new QPrinter(); } // stop refresh temporarily if (m_zoomView->getRefreshStatus()) { slotToggleRefresh(); toggled = true; } const QImage pixmap(m_zoomView->getImage()); // use some AI to get the best orientation if(pixmap.width() > pixmap.height()) { m_printer->setOrientation(QPrinter::Landscape); } else { m_printer->setOrientation(QPrinter::Portrait); } QPrintDialog *printDialog = KdePrint::createPrintDialog(m_printer, this); if (printDialog->exec()) { QPainter paint; if(!paint.begin(m_printer)) { delete printDialog; return; } // draw the pixmap paint.drawImage(0, 0, pixmap); // end the painting paint.end(); } if(toggled) { slotToggleRefresh(); } delete printDialog; #endif // QT_NO_PRINTER } void KmagApp::slotFileQuit() { saveOptions(); // close the first window, the list makes the next one the first again. // This ensures that queryClose() is called on each window to ask for closing KMainWindow* w; if (!memberList().isEmpty()) { for (int i = 0; i < memberList().size(); ++i) { w = memberList().at(i); // only close the window if the closeEvent is accepted. If the user presses Cancel on the saveModified() dialog, // the window and the application stay open. if(!w->close()) break; #ifdef __GNUC__ #warning "kde4: now memberList() is constant => we can't remove some element!" #endif //memberList()->removeRef(w); } } } void KmagApp::copyToClipBoard() { QClipboard *cb=KApplication::clipboard(); cb->setPixmap(QPixmap::fromImage(m_zoomView->getImage())); } void KmagApp::slotShowMenu() { /////////////////////////////////////////////////////////////////// // turn Menu on or off if(!m_pShowMenu->isChecked()) { menuBar()->hide(); } else { menuBar()->show(); } } void KmagApp::slotConfKeys() { KShortcutsDialog::configure( actionCollection() ); } void KmagApp::slotEditToolbars() { KConfigGroup cg( KGlobal::config(), "MainWindow" ); saveMainWindowSettings( cg ); QPointer dlg = new KEditToolBar( actionCollection() ); connect(dlg, SIGNAL(newToolBarConfig()), this, SLOT(slotNewToolbarConfig()) ); if ( dlg->exec() ) createGUI(); delete dlg; } void KmagApp::slotNewToolbarConfig() { applyMainWindowSettings( KGlobal::config()->group( "MainWindow" ) ); createGUI(); } diff --git a/kmag.h b/kmag.h index 5caeaf2..23ccfb9 100644 --- a/kmag.h +++ b/kmag.h @@ -1,239 +1,240 @@ /*************************************************************************** kmag.h - description ------------------- begin : Mon Feb 12 23:45:41 EST 2001 copyright : (C) 2001 by Sarang Lakare email : sarang@users.sourceforge.net copyright : (C) 2003-2004 by Olaf Schmidt email : ojschmidt@kde.org copyright : (C) 2008 by Matthew Woehlke email : mw_triad@users.sourceforge.net copyright (C) 2010 Sebastian Sauer email sebsauer@kdab.com ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef KMAG_H #define KMAG_H #include "kmagzoomview.h" #include "focustrackconfig.h" // include files for Qt -#include -#include +#include +#include // include files for KDE #include -#include +#include +#include #include -#include +#include /** * The base class for Kmag application windows. It sets up the main * window and reads the config file as well as providing a menubar, toolbar * and statusbar. An instance of KmagView creates your center view, which is connected * to the window's Doc object. * KmagApp reimplements the methods that KXmlGuiWindow provides for main window handling and supports * full session management as well as using KActions. * @see KXmlGuiWindow * @see KApplication * @see KConfig * * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team. * @version KDevelop version 1.2 code generation */ class KmagApp : public KXmlGuiWindow { Q_OBJECT public: /** * Construtor of KmagApp, calls all init functions to create the application. */ explicit KmagApp(QWidget* parent=0, const char* name=0); /// Default destructor ~KmagApp(); protected: /** save general Options like all bar positions and status as well as the geometry and the recent file list to the configuration * file */ void saveOptions(); /** read general Options again and initialize all variables like the recent file list */ void readOptions(); /** initializes the KActions of the application */ void initActions(); /** creates the centerwidget of the KTMainWindow instance and sets it as the view */ void initView(); /// Initialize all connections void initConnections(); virtual bool queryClose(); /// Catch context menu events void contextMenuEvent ( QContextMenuEvent * e ); public slots: /** open a new application window by creating a new instance of KmagApp */ void slotFileNewWindow(); /** print the actual file */ void slotFilePrint(); void slotFileQuit(); /** put the marked text/object into the clipboard */ void copyToClipBoard(); /// Toggle the refreshing of the window void slotToggleRefresh(); void slotModeChanged(); void slotModeWholeScreen(); void slotModeSelWin(); /// Zooms in void zoomIn(); /// Zooms out void zoomOut(); /// Save the zoomed image void saveZoomPixmap(); /// Sets the zoom index to index void setZoomIndex(int index); /// Sets the rotation index to index void setRotationIndex(int index); /// Sets the fps index to index void setFPSIndex(int index); /// Sets the color index to index void setColorIndex(int index); /// Shows/hides the mouse cursor void showMouseCursor(bool show); void slotShowMenu(); void slotToggleHideCursor(); void slotStaysOnTop(); /// Opens shortcut key configuration dialog void slotConfKeys(); /// Called when toolbar config is updated void slotNewToolbarConfig(); /// Called when "configure toolbar" is clicked void slotEditToolbars(); void slotChangeZoomBoxIndex(int index); void slotChangeRotationBoxIndex(int index); void slotChangeFPSIndex(int index); void slotChangeColorIndex(int index); signals: /// This signal is raised whenever the index into the zoom array is changed void updateZoomIndex(int); /// This signal is raised whenever the zoom value changes void updateZoomValue(float); /// This signal is raised whenever the index into the rotation array is changed void updateRotationIndex(int); /// This signal is raised whenever the rotation value changes void updateRotationValue(int); /// This signal is raised whenever the index into the fps array is changed void updateFPSIndex(int); /// This signal is raised whenever the fps value changes void updateFPSValue(float); /// This signal is raised whenever the index into the color array is changed void updateColorIndex(int); /// This signal is raised whenever the color value changes void updateColorValue(int); private: /// the configuration object of the application KSharedConfigPtr config; // KAction pointers to enable/disable actions - KAction *fileNewWindow, *m_pSnapshot, *m_pCopy, *m_keyConf, *m_toolConf; + QAction *fileNewWindow, *m_pSnapshot, *m_pCopy, *m_keyConf, *m_toolConf; QAction *m_pPrint; QAction *m_pZoomIn; QAction *m_pZoomOut; QAction *m_pQuit; - KAction *refreshSwitch; + QAction *refreshSwitch; KToggleAction *m_pShowMenu; KSelectAction *m_pZoomBox, *m_pRotationBox, *m_pFPSBox, *m_pColorBox; /// zoom slider KIntNumInput *m_zoomSlider; /// Current index into the zoomArray unsigned int m_zoomIndex; /// Current index into the rotationArray unsigned int m_rotationIndex; /// Current index into the fpsArray unsigned int m_fpsIndex; /// Current index into the colorArray unsigned int m_colorIndex; QStringList zoomArrayString; QVector zoomArray; QStringList rotationArrayString; QVector rotationArray; QStringList fpsArrayString; QVector fpsArray; QStringList colorArrayString; QVector colorArray; KMagZoomView* m_zoomView; KToggleAction *m_hideCursor, *m_staysOnTop; KToggleAction *m_modeFollowMouse, *m_modeFollowFocus, *m_modeWholeScreen, *m_modeSelWin; /// Stores the non-zero cursor type to be used unsigned int m_mouseCursorType; unsigned int m_defaultMouseCursorType; #ifndef QT_NO_PRINTER // Keep QPrinter so settings persist QPrinter *m_printer; #endif // QT_NO_PRINTER }; #endif // KMAG_H diff --git a/kmagselrect.cpp b/kmagselrect.cpp index 456c1ee..a5777c1 100644 --- a/kmagselrect.cpp +++ b/kmagselrect.cpp @@ -1,378 +1,378 @@ /*************************************************************************** kmagselrect.cpp - description ------------------- begin : Mon Feb 12 23:45:41 EST 2001 copyright : (C) 2001-2003 by Sarang Lakare email : sarang#users.sf.net copyright : (C) 2003-2004 by Olaf Schmidt email : ojschmidt@kde.org ***************************************************************************/ /*************************************************************************** * * * 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 "kmagselrect.h" #include "kmagselrect.moc" -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include static uchar line_bits[] = {0x2d, 0x96, 0x4b, 0xa5, 0xd2, 0x69, 0xb4, 0x5a}; static QColor titleColor = QColor (0,0,128); static QColor titleBtnColor = QColor (255,255,0); static QColor textColor = QColor (255,255,255); static int frameSize = 10; static int titleSize = 24; void setTitleColors (const QColor &title, const QColor &text, const QColor &titleBtn) { titleColor = title; titleBtnColor = titleBtn; textColor = text; } void setFrameSize (int size) { frameSize = size; } void setTitleSize (int size) { titleSize = size; } QColor getTitleColor () { return titleColor; } QColor getTitleBtnColor () { return titleBtnColor; } QColor getTextColor () { return textColor; } int getFrameSize () { return frameSize; } int getTitleSize () { if (titleSize > frameSize) return titleSize; else return frameSize; } //-------------------------------------------------------------------------- // Construction //-------------------------------------------------------------------------- KMagSelRect::KMagSelRect(QWidget *parent) : QRect() { init(parent); } KMagSelRect::KMagSelRect(const QPoint &topLeft, const QPoint &bottomRight, QWidget *parent) : QRect(topLeft, bottomRight) { init(parent); } KMagSelRect::KMagSelRect(const QPoint &topLeft, const QSize &size, QWidget *parent) : QRect(topLeft, size) { init(parent); } KMagSelRect::KMagSelRect(int left, int top, int width, int height, QWidget *parent) : QRect(left, top, width, height) { init(parent); } void KMagSelRect::init(QWidget *parent) { // Make sure parent is the window itself, not a widget within the window if (parent != 0) while (parent->parentWidget() != 0) parent=parent->parentWidget(); selectionwindow = 0; selWindowParent = parent; m_alwaysVisible = false; } KMagSelRect::~KMagSelRect() { } //-------------------------------------------------------------------------- // //-------------------------------------------------------------------------- bool KMagSelRect::visible() { return (selectionwindow != 0); } void KMagSelRect::alwaysVisible(bool visible) { m_alwaysVisible = visible; } //-------------------------------------------------------------------------- // Slots //-------------------------------------------------------------------------- void KMagSelRect::show() { if (selectionwindow == 0) { selectionwindow = new KMagSelWin (selWindowParent); selectionwindow->setObjectName( QLatin1String("selectionwindow" )); connect (selectionwindow, SIGNAL (resized()), this, SLOT (selWinResized())); update(); selectionwindow->show(); selWindowParent->activateWindow(); } } void KMagSelRect::hide() { if(m_alwaysVisible) return; if (selectionwindow != 0) { selectionwindow->hide(); delete selectionwindow; selectionwindow = 0; } } void KMagSelRect::update() { if (selectionwindow != 0) selectionwindow->setSelRect (QRect (topLeft(), bottomRight())); } void KMagSelRect::selWinResized() { if (selectionwindow != 0) { QRect newRect = selectionwindow->getSelRect(); setRect (newRect.x(), newRect.y(), newRect.width(), newRect.height()); } } //-------------------------------------------------------------------------- // KMagSelWin //-------------------------------------------------------------------------- void setPaletteColor(QWidget* w, QPalette::ColorRole r, const QColor& c) { QPalette p = w->palette(); p.setColor(r, c); w->setPalette(p); } KMagSelWin::KMagSelWin ( QWidget * parent, Qt::WFlags ) : QWidget(parent) //Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_StaysOnTop | Qt::WType_TopLevel | Qt::WX11BypassWM) { setWindowFlags( Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); QPalette p = palette(); p.setBrush(backgroundRole(), QBrush(QBitmap::fromData( QSize(8, 8), line_bits))); setPalette(p); titleBar = new KMagSelWinCorner (this); titleBar->setObjectName( QLatin1String("titlebar" )); setPaletteColor(titleBar, QPalette::Background, getTitleColor()); setPaletteColor(titleBar, QPalette::Foreground, getTextColor()); titleBar->setText(i18n("Selection Window")+QLatin1String( " - " )+i18n("KMagnifier")); connect (titleBar, SIGNAL (startResizing()), this, SLOT (startResizing())); connect (titleBar, SIGNAL (resized(QPoint)), this, SLOT (titleMoved(QPoint))); topLeftCorner = new KMagSelWinCorner (this); topLeftCorner->setObjectName( QLatin1String("topleft" )); topLeftCorner->setCursor (Qt::SizeFDiagCursor); setPaletteColor(topLeftCorner, QPalette::Background, getTitleBtnColor()); connect (topLeftCorner, SIGNAL (startResizing()), this, SLOT (startResizing())); connect (topLeftCorner, SIGNAL (resized(QPoint)), this, SLOT (topLeftResized(QPoint))); topRightCorner = new KMagSelWinCorner (this); topRightCorner->setObjectName( QLatin1String("topright" )); topRightCorner->setCursor (Qt::SizeBDiagCursor); setPaletteColor(topRightCorner, QPalette::Background, getTitleBtnColor ()); connect (topRightCorner, SIGNAL (startResizing()), this, SLOT (startResizing())); connect (topRightCorner, SIGNAL (resized(QPoint)), this, SLOT (topRightResized(QPoint))); bottomLeftCorner = new KMagSelWinCorner (this); bottomLeftCorner->setObjectName( QLatin1String("bottomleft" )); bottomLeftCorner->setCursor (Qt::SizeBDiagCursor); setPaletteColor(bottomLeftCorner, QPalette::Background, getTitleBtnColor()); connect (bottomLeftCorner, SIGNAL (startResizing()), this, SLOT (startResizing())); connect (bottomLeftCorner, SIGNAL (resized(QPoint)), this, SLOT (bottomLeftResized(QPoint))); bottomRightCorner = new KMagSelWinCorner (this); bottomRightCorner->setObjectName( QLatin1String("bottomright" )); bottomRightCorner->setCursor (Qt::SizeFDiagCursor); setPaletteColor(bottomRightCorner, QPalette::Background, getTitleBtnColor ()); connect (bottomRightCorner, SIGNAL (startResizing()), this, SLOT (startResizing())); connect (bottomRightCorner, SIGNAL (resized(QPoint)), this, SLOT (bottomRightResized(QPoint))); } KMagSelWin::~KMagSelWin() { delete titleBar; delete topLeftCorner; delete topRightCorner; delete bottomLeftCorner; delete bottomRightCorner; } void KMagSelWin::setSelRect (const QRect &_selRect) { QRect selRect = _selRect.normalized(); if (selRect.left() < 0) selRect.setLeft (0); if (selRect.top() < 0) selRect.setTop (0); if (selRect.right() > QApplication::desktop()->width()) selRect.setRight (QApplication::desktop()->width()); if (selRect.bottom() > QApplication::desktop()->height()) selRect.setBottom (QApplication::desktop()->height()); setGeometry ( selRect.left() - getFrameSize(), selRect.top() - getTitleSize() - 2, selRect.width() + getFrameSize() + getFrameSize(), selRect.height() + getFrameSize() + getTitleSize()+2); int w = getFrameSize(); if (selRect.width() < w+w) w = static_cast(selRect.width()/2); int h = getFrameSize(); if (selRect.height() < h+h) h = static_cast(selRect.height()/2); setMask (QRegion (QRect (0, 0, width(), height ())) - QRegion (QRect (getFrameSize(), getTitleSize()+2, selRect.width(), selRect.height())) - QRegion (QRect (0, 0, getFrameSize()+w, getTitleSize()+2-getFrameSize())) - QRegion (QRect (width()-getFrameSize()-w, 0, getFrameSize()+w, getTitleSize()+2-getFrameSize())) - QRegion (QRect (0, getTitleSize()+2+h, getFrameSize()-2, selRect.height()-h-h)) - QRegion (QRect (width()-getFrameSize()+2, getTitleSize()+2+h, getFrameSize()-2, selRect.height()-h-h)) - QRegion (QRect (getFrameSize()+w, height()-getFrameSize()+2, selRect.width()-w-w, getFrameSize()-2))); titleBar->setGeometry (getFrameSize()+w, 0, selRect.width()-h-h, getTitleSize()); topLeftCorner->setGeometry (0, getTitleSize()+2-getFrameSize(), getFrameSize()+w, getFrameSize()+h); topRightCorner->setGeometry (width()-getFrameSize()-w, getTitleSize()+2-getFrameSize(), getFrameSize()+w, getFrameSize()+h); bottomLeftCorner->setGeometry (0, height()-getFrameSize()-h, getFrameSize()+w, getFrameSize()+h); bottomRightCorner->setGeometry (width()-getFrameSize()-w, height()-getFrameSize()-h, getFrameSize()+w, getFrameSize()+h); } QRect KMagSelWin::getSelRect () { return QRect ( x() + getFrameSize(), y() + getTitleSize()+2, width() - getFrameSize() - getFrameSize(), height() - getFrameSize() - getTitleSize()-2); } void KMagSelWin::startResizing () { oldSelRect = getSelRect(); } void KMagSelWin::titleMoved (const QPoint &offset) { QRect selRect = oldSelRect; selRect.translate (offset.x(), offset.y()); setSelRect (selRect); emit resized (); } void KMagSelWin::topLeftResized (const QPoint &offset) { setSelRect (QRect(oldSelRect.topLeft() + offset, oldSelRect.bottomRight ())); emit resized(); } void KMagSelWin::topRightResized (const QPoint &offset) { setSelRect (QRect(oldSelRect.topRight() + offset, oldSelRect.bottomLeft ())); emit resized(); } void KMagSelWin::bottomLeftResized (const QPoint &offset) { setSelRect (QRect(oldSelRect.bottomLeft() + offset, oldSelRect.topRight ())); emit resized(); } void KMagSelWin::bottomRightResized (const QPoint &offset) { setSelRect (QRect(oldSelRect.bottomRight() + offset, oldSelRect.topLeft())); emit resized(); } //-------------------------------------------------------------------------- // KMagSelWinCorner //-------------------------------------------------------------------------- KMagSelWinCorner::KMagSelWinCorner ( QWidget * parent, Qt::WFlags f ) : QLabel (parent, f) { setFrameStyle (QFrame::WinPanel | QFrame::Raised); setLineWidth (1); } KMagSelWinCorner::~KMagSelWinCorner() { } void KMagSelWinCorner::mousePressEvent ( QMouseEvent * e ) { oldPos = e->globalPos (); emit startResizing (); } void KMagSelWinCorner::mouseReleaseEvent ( QMouseEvent * e ) { setFrameShadow (QFrame::Raised); emit resized (e->globalPos () - oldPos); } void KMagSelWinCorner::mouseMoveEvent ( QMouseEvent * e ) { emit resized (e->globalPos () - oldPos); } diff --git a/kmagselrect.h b/kmagselrect.h index d219fe8..2445a90 100644 --- a/kmagselrect.h +++ b/kmagselrect.h @@ -1,145 +1,145 @@ /*************************************************************************** kmagselrect.h - description ------------------- begin : Mon Feb 12 23:45:41 EST 2001 copyright : (C) 2001-2003 by Sarang Lakare email : sarang#users.sf.net copyright : (C) 2003-2004 by Olaf Schmidt email : ojschmidt@kde.org ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef KMAGSELRECT_H #define KMAGSELRECT_H #include // Qt includes -#include -#include -#include -#include +#include +#include +#include +#include class KMagSelWinCorner : public QLabel { Q_OBJECT public: explicit KMagSelWinCorner ( QWidget * parent = 0, Qt::WFlags f = 0 ); virtual ~KMagSelWinCorner(); signals: void startResizing (); void resized ( QPoint offset ); protected: QPoint oldPos; virtual void mousePressEvent ( QMouseEvent * e ); virtual void mouseReleaseEvent ( QMouseEvent * e ); virtual void mouseMoveEvent ( QMouseEvent * e ); }; class KMagSelWin : public QWidget { Q_OBJECT public: explicit KMagSelWin ( QWidget * parent = 0, Qt::WFlags f = 0 ); virtual ~KMagSelWin(); void setSelRect ( const QRect & selRect ); QRect getSelRect (); public slots: void startResizing (); void titleMoved ( const QPoint & offset ); void topLeftResized ( const QPoint & offset ); void topRightResized ( const QPoint & offset ); void bottomLeftResized ( const QPoint & offset ); void bottomRightResized ( const QPoint & offset ); signals: void resized(); protected: QRect oldSelRect; KMagSelWinCorner *titleBar; KMagSelWinCorner *topLeftCorner; KMagSelWinCorner *topRightCorner; KMagSelWinCorner *bottomLeftCorner; KMagSelWinCorner *bottomRightCorner; }; /** * This class stores the selected rectangular area for grabbing. It also displays the * rectangular area on demand. * * @author Original : Michael Forster * @author Current : Sarang Lakare */ class KMagSelRect : public QObject, public QRect { Q_OBJECT public: explicit KMagSelRect(QWidget *parent=0); KMagSelRect(const QPoint &topLeft, const QPoint &bottomRight, QWidget *parent=0); KMagSelRect(const QPoint &topLeft, const QSize &size, QWidget *parent=0); KMagSelRect(int left, int top, int width, int height, QWidget *selWindowParent=0); virtual ~KMagSelRect(); bool visible(); /// Makes the rectangle always visible void alwaysVisible(bool visible=true); /// Returns true if always visible is set bool getAlwaysVisible() const { return (m_alwaysVisible); } public slots: void show(); void hide(); void update(); void selWinResized(); protected: void init(QWidget *); QWidget *selWindowParent; KMagSelWin *selectionwindow; bool m_alwaysVisible; }; void setTitleColors (const QColor & title, const QColor & text, const QColor & titleBtn); void setFrameSize (int size); #endif // KMAGSELRECT_H diff --git a/kmagzoomview.cpp b/kmagzoomview.cpp index 4613cc0..85a6926 100644 --- a/kmagzoomview.cpp +++ b/kmagzoomview.cpp @@ -1,1151 +1,1150 @@ /*************************************************************************** kmagview.cpp - description ------------------- begin : Mon Feb 12 23:45:41 EST 2001 copyright : (C) 2001-2003 by Sarang Lakare email : sarang#users.sourceforge.net copyright : (C) 2003-2004 by Olaf Schmidt email : ojschmidt@kde.org copyright : (C) 2008 by Matthew Woehlke email : mw_triad@users.sourceforge.net copyright (C) 2010 Sebastian Sauer email sebsauer@kdab.com ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ // application specific includes #include "kmagzoomview.h" #include "kmagzoomview.moc" #include "colorsim.h" // include files for Qt -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // include files for KDE #include #include #include #include #ifdef QAccessibilityClient_FOUND #include #endif // include bitmaps for cursors static uchar left_ptr_bits[] = { 0x00, 0x00, 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01, 0xf8, 0x03, 0xf8, 0x07, 0xf8, 0x00, 0xd8, 0x00, 0x88, 0x01, 0x80, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00}; static uchar left_ptrmsk_bits[] = { 0x0c, 0x00, 0x1c, 0x00, 0x3c, 0x00, 0x7c, 0x00, 0xfc, 0x00, 0xfc, 0x01, 0xfc, 0x03, 0xfc, 0x07, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x01, 0xdc, 0x03, 0xcc, 0x03, 0x80, 0x07, 0x80, 0x07, 0x00, 0x03}; static uchar phand_bits[] = { 0x00, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x7e, 0x04, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x70, 0x08, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x70, 0x14, 0x00, 0x00, 0x08, 0x22, 0x00, 0x00, 0x30, 0x41, 0x00, 0x00, 0xc0, 0x20, 0x00, 0x00, 0x40, 0x12, 0x00, 0x00, 0x80, 0x08, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static uchar phandm_bits[] = { 0xfe, 0x01, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0x1f, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0xf8, 0xff, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x3f, 0x00, 0x00, 0xc0, 0x1f, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; KMagZoomView::KMagZoomView(QWidget *parent, const char *name) : QAbstractScrollArea(parent), m_selRect(0, 0, 128, 128, this), m_grabTimer(parent), m_mouseViewTimer(parent), m_latestCursorPos(0,0), m_followMouse(false), m_followFocus(false), m_showMouse(1), m_zoom(1.0), m_rotation(0), m_colormode(0), m_fitToWindow(true) { setObjectName( QLatin1String( name )); viewport()->setMouseTracking(true); viewport()->setAttribute(Qt::WA_NoSystemBackground, true); viewport()->setAutoFillBackground(false); viewport()->setFocusPolicy(Qt::StrongFocus); // init the zoom matrix setupMatrix(); m_ctrlKeyPressed = false; m_shiftKeyPressed = false; m_refreshSwitch = true; m_refreshSwitchStateOnHide = m_refreshSwitch; // set the refresh rate setRefreshRate(10); // connect it to grabFrame() connect(&m_grabTimer, SIGNAL(timeout()), SLOT(grabFrame())); // start the grabTimer m_grabTimer.start(static_cast(1000.0/m_fps)); // connect it to updateMouseView() connect(&m_mouseViewTimer, SIGNAL(timeout()), SLOT(updateMouseView())); // start the grabTimer @ 25 frames per second! m_mouseViewTimer.start(40); this->setWhatsThis( i18n("This is the main window which shows the contents of the\ selected region. The contents will be magnified according to the zoom level that is set.")); // different ways to show the cursor. m_showMouseTypes << QLatin1String( "Hidden" ) << QLatin1String( "Box" ) << QLatin1String( "Arrow" ) << QLatin1String( "Actual" ); if(m_fitToWindow) fitToWindow(); #ifdef QAccessibilityClient_FOUND //subscribe to focus events from registry m_registry.subscribeEventListeners(QAccessibleClient::Registry::Focus | QAccessibleClient::Registry::TextCaretMoved); #endif } KMagZoomView::~KMagZoomView() { } int KMagZoomView::contentsX() const { return horizontalScrollBar()->value(); } int KMagZoomView::contentsY() const { return verticalScrollBar()->value(); } int KMagZoomView::contentsWidth() const { return horizontalScrollBar()->pageStep(); } int KMagZoomView::contentsHeight() const { return verticalScrollBar()->pageStep(); } int KMagZoomView::visibleWidth() const { return viewport()->width(); } int KMagZoomView::visibleHeight() const { return viewport()->height(); } void KMagZoomView::setContentsPos(int x, int y) { horizontalScrollBar()->setValue(x); verticalScrollBar()->setValue(y); } void KMagZoomView::setupMatrix() { m_zoomMatrix.reset(); m_zoomMatrix.scale(m_zoom, m_zoom); m_zoomMatrix.rotate(m_rotation); } /** * This function will set/reset mouse following of grab window. */ void KMagZoomView::followMouse(bool follow) { m_followMouse = follow; m_mouseMode = Normal; if(follow) { setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); } else { setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn); setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn); } } #ifdef QAccessibilityClient_FOUND void KMagZoomView::followBoth(bool follow) { m_followBoth = follow; if(follow){ m_followMouse = true; m_followFocus = false; setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); connect(&m_registry, SIGNAL(focusChanged(QAccessibleClient::AccessibleObject)), this, SLOT(focusChanged(QAccessibleClient::AccessibleObject))); connect(&m_registry, SIGNAL(textCaretMoved(QAccessibleClient::AccessibleObject,int)), this, SLOT(focusChanged(QAccessibleClient::AccessibleObject))); } else { setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn); setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn); disconnect(this, SLOT(focusChanged(QAccessibleClient::AccessibleObject))); } } /** * This function will set/reset keyboard focus following of grab window. */ void KMagZoomView::followFocus(bool follow) { if(m_followFocus == follow) return; m_followFocus = follow; m_mouseMode = Normal; if(follow) { setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); connect(&m_registry,SIGNAL(focusChanged(QAccessibleClient::AccessibleObject)), this, SLOT(focusChanged(QAccessibleClient::AccessibleObject))); connect(&m_registry, SIGNAL(textCaretMoved(QAccessibleClient::AccessibleObject,int)), this, SLOT(focusChanged(QAccessibleClient::AccessibleObject))); } else { setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn); setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn); disconnect(this, SLOT(focusChanged(QAccessibleClient::AccessibleObject))); } } void KMagZoomView::focusChanged(const QAccessibleClient::AccessibleObject &object) { m_oldFocus = object.focusPoint(); if(m_followBoth && !m_selRect.contains(m_oldFocus)) { QCursor::setPos(m_oldFocus); m_followFocus = true; m_followMouse = false; } } #endif /** * Called when the widget is hidden. Stop refresh when this happens. */ void KMagZoomView::hideEvent( QHideEvent* ) { // Save the state of the refresh switch.. the state will be restored // when showEvent is called m_refreshSwitchStateOnHide = m_refreshSwitch; // Check if refresh is ON if(m_refreshSwitch) { toggleRefresh(); } } /** * Called when the widget is shown. Start refresh when this happens. */ void KMagZoomView::showEvent( QShowEvent* ) { // Check if refresh switch was ON when hide was called and if currently it is OFF if(m_refreshSwitchStateOnHide && !m_refreshSwitch) { // start the refresh in that case toggleRefresh(); } } /** * Called when the widget is resized. Check if fitToWindow is active when this happens. */ void KMagZoomView::resizeEvent( QResizeEvent * e ) { horizontalScrollBar()->setRange(0, contentsWidth() - visibleWidth()); verticalScrollBar()->setRange(0, contentsHeight() - visibleHeight()); QAbstractScrollArea::resizeEvent(e); if(m_fitToWindow) fitToWindow(); } /** * Called when the widget is to be repainted. * * @param p */ void KMagZoomView::paintEvent(QPaintEvent *e) { if(m_coloredPixmap.isNull()) return; QPainter p(viewport()); int clipx = e->rect().x(); int clipy = e->rect().x(); int clipw = e->rect().width(); int cliph = e->rect().height(); // Paint empty areas Qt::black if (contentsX()+contentsWidth() < visibleWidth()) p.fillRect ( QRect (contentsX()+contentsWidth(), clipy, visibleWidth()-contentsX()-contentsWidth(), cliph) & e->rect(), Qt::black); if (contentsY()+contentsHeight() < visibleHeight()) p.fillRect ( QRect (clipx, contentsY()+contentsHeight(), clipw, visibleHeight()-contentsY()-contentsHeight()) & e->rect(), Qt::black); p.translate(visibleWidth() / 2.0, visibleHeight() / 2.0); p.setMatrix(m_zoomMatrix, true); p.translate(-m_coloredPixmap.width() / 2.0, -m_coloredPixmap.height() / 2.0); p.drawPixmap(QPoint(clipx-contentsX(), clipy-contentsY()), m_coloredPixmap); p.end(); if (m_showMouse) paintMouseCursor(viewport(), calcMousePos (m_refreshSwitch)); } /** * Draws the mouse cursor according to the current selection of the type of * mouse cursor to draw. */ void KMagZoomView::paintMouseCursor(QPaintDevice *dev, const QPoint &mousePos) { if(!dev) return; // painter for the zoom view QPainter pz(dev); // How to show the mouse : switch(m_showMouse) { case 1: // 1. Square around the pixel pz.setPen(Qt::white); #ifdef __GNUC__ #warning "Port Qt4 pz.setRasterOp(Qt::XorROP);"; #endif //pz.setRasterOp(Qt::XorROP); pz.drawRect(mousePos.x()-1, mousePos.y()-1, (int)m_zoom+2, (int)m_zoom+2); break; case 2: { // 2. Arrow cursor pz.setPen(Qt::black); pz.setBackground(Qt::white); QPixmap sCursor(16, 16); QBitmap cursor = QBitmap::fromData( QSize(16, 16), left_ptr_bits); QBitmap mask = QBitmap::fromData( QSize(16, 16), left_ptrmsk_bits); sCursor.setMask(mask); QPainter p(&sCursor); p.setPen(Qt::gray); p.drawPixmap(0, 0, mask); p.setPen(Qt::black); p.drawPixmap(0, 0, cursor); p.end(); sCursor = sCursor.transformed(m_zoomMatrix); // since hot spot is at 3,1 if (m_rotation == 0) pz.drawPixmap(mousePos.x()-(int)(3.0*m_zoom), mousePos.y()-(int)m_zoom, sCursor); else if (m_rotation == 90) pz.drawPixmap(mousePos.x()-(int)(16.0*m_zoom), mousePos.y()-(int)(3.0*m_zoom), sCursor); else if (m_rotation == 180) pz.drawPixmap(mousePos.x()-(int)(13.0*m_zoom), mousePos.y()-(int)(16.0*m_zoom), sCursor); else if (m_rotation == 270) pz.drawPixmap(mousePos.x()-(int)m_zoom, mousePos.y()-(int)(13.0*m_zoom), sCursor); } break; case 3: { // 3. Actual cursor // Get the current cursor type QWidget *dummy = KApplication::topLevelAt(QCursor::pos()); if(!dummy) break; kDebug() << ">" << dummy->objectName() << ":" << dummy->cursor().shape() << "-"; switch(this->cursor().shape()) { case Qt::ArrowCursor : { // 2. Arrow cursor pz.setPen(Qt::black); pz.setBackground(Qt::white); QBitmap sCursor = QBitmap::fromData( QSize(16, 16), left_ptr_bits); QBitmap mask = QBitmap::fromData( QSize(16, 16), left_ptrmsk_bits); sCursor.setMask(mask); sCursor = sCursor.transformed(m_zoomMatrix); // since hot spot is at 3,1 pz.drawPixmap(mousePos.x()-(int)(3.0*m_zoom), mousePos.y()-(int)m_zoom, sCursor); } break; default: QBitmap sCursor = QBitmap::fromData( QSize(32, 32), phand_bits); QBitmap mask = QBitmap::fromData( QSize(32, 32), phandm_bits); sCursor.setMask(mask); pz.drawPixmap(mousePos.x(), mousePos.y(), sCursor); break; } // switch(cursor) } break; default: // do not show anything break; } // switch(m_showMouse) } QPoint KMagZoomView::calcMousePos(bool updateMousePos) { // get position of mouse wrt selRect if(updateMousePos) { // get a new position only if asked m_latestCursorPos = QCursor::pos(); m_latestCursorPos -= QPoint(m_selRect.x(), m_selRect.y()); } // get coordinates of the pixel w.r.t. the zoomed pixmap if (m_rotation == 90) return QPoint ((int)((float)(m_selRect.height()-m_latestCursorPos.y())*m_zoom), (int)((float)m_latestCursorPos.x()*m_zoom)); else if (m_rotation == 180) return QPoint ((int)((float)(m_selRect.width()-m_latestCursorPos.x())*m_zoom), (int)((float)(m_selRect.height()-m_latestCursorPos.y())*m_zoom)); else if (m_rotation == 270) return QPoint ((int)((float)m_latestCursorPos.y()*m_zoom), (int)((float)(m_selRect.width()-m_latestCursorPos.x())*m_zoom)); else return QPoint ((int)((float)m_latestCursorPos.x()*m_zoom), (int)((float)m_latestCursorPos.y()*m_zoom)); } // MOUSE ACTIONS /** * Called when mouse is clicked inside the window. * * @param e */ void KMagZoomView::mousePressEvent(QMouseEvent *e) { switch(e->button()) { case Qt::LeftButton : if(m_ctrlKeyPressed) { // check if currently in resize mode // don't do anything if fitToWindow is enabled if ((m_mouseMode != ResizeSelection) && !m_fitToWindow) { // set the mode to ResizeSelection m_mouseMode = ResizeSelection; // set mouse cursor to "resize all direction" setCursor(Qt::SizeAllCursor); // backup the old position m_oldMousePos.setX(e->globalX()); m_oldMousePos.setY(e->globalY()); // set the cursor position to the bottom-right of the selected region QCursor::setPos(m_selRect.bottomRight()); // show the selection rectangle m_selRect.show(); } else { // ignore this button press.. so it goes to the parent e->ignore(); } } else if(m_shiftKeyPressed) { // check if currently in move mode // don't do anything if follow mouse is enabled if ((m_mouseMode != MoveSelection) && !m_followMouse) { m_mouseMode = MoveSelection; // set mouse cursor to cross hair setCursor(Qt::CrossCursor); // backup the old position m_oldMousePos.setX(e->globalX()); m_oldMousePos.setY(e->globalY()); // set the cursor position to the center of the selected region QCursor::setPos(m_selRect.center()); // show the selected rectangle m_selRect.show(); } else { // ignore this button press.. so it goes to the parent e->ignore(); } } else { // check if currently in move mode // don't do anything if follow mouse is enabled if ((m_mouseMode != GrabSelection) && !m_followMouse) { m_mouseMode = GrabSelection; // set mouse cursor to hand setCursor(Qt::PointingHandCursor); // store the old position m_oldMousePos.setX(e->globalX()); m_oldMousePos.setY(e->globalY()); m_oldCenter = m_selRect.center(); // show the selected rectangle m_selRect.show(); } else { // ignore this button press.. so it goes to the parent e->ignore(); } } break; case Qt::MidButton : // check if currently in move mode // don't do anything if follow mouse is enabled if ((m_mouseMode != MoveSelection) && !m_followMouse) { m_mouseMode = MoveSelection; // set mouse cursor to cross hair setCursor(Qt::CrossCursor); // backup the old position m_oldMousePos.setX(e->globalX()); m_oldMousePos.setY(e->globalY()); // set the cursor position to the center of the selected region QCursor::setPos(m_selRect.center()); // show the selected rectangle m_selRect.show(); } else { // ignore this button press.. so it goes to the parent e->ignore(); } break; // do nothing default: // ignore this button press.. so it goes to the parent e->ignore(); break; } } /** * Called when a mouse button is released * * @param e */ void KMagZoomView::mouseReleaseEvent(QMouseEvent *e) { switch(e->button()) { case Qt::LeftButton : case Qt::MidButton : // check if currently in move mode if(m_mouseMode == MoveSelection) { // hide the selection window m_selRect.hide(); // set the mouse mode to normal m_mouseMode = Normal; // restore the cursor shape setCursor(Qt::ArrowCursor); // restore the cursor position QCursor::setPos(m_oldMousePos); } else if(m_mouseMode == ResizeSelection) { // hide the selection window m_selRect.hide(); // set the mouse mode to normal m_mouseMode = Normal; // restore the cursor shape setCursor(Qt::ArrowCursor); // restore the cursor position QCursor::setPos(m_oldMousePos); } else if(m_mouseMode == GrabSelection) { // hide the selection window m_selRect.hide(); // set the mouse mode to normal m_mouseMode = Normal; // restore the cursor shape setCursor(Qt::ArrowCursor); } break; case Qt::RightButton : break; case Qt::NoButton : break; // do nothing default: ; } } /** * Called when mouse is moved inside the window * * @param e */ void KMagZoomView::mouseMoveEvent(QMouseEvent *e) { if(m_mouseMode == ResizeSelection) { // In resize selection mode // set the current mouse position as the bottom, right corner m_selRect.setRight(e->globalX()); m_selRect.setBottom(e->globalY()); m_selRect.update(); grabFrame(); } else if(m_mouseMode == MoveSelection) { QPoint newCenter; // set new center to be the current mouse position newCenter = e->globalPos(); // make sure the mouse position is not taking the grab window outside // the display if(newCenter.x() < m_selRect.width()/2) { // set X to the minimum possible X newCenter.setX(m_selRect.width()/2); } else if(newCenter.x() >= QApplication::desktop()->width()-m_selRect.width()/2) { // set X to the maximum possible X newCenter.setX(QApplication::desktop()->width()-m_selRect.width()/2-1); } if(newCenter.y() < m_selRect.height()/2) { // set Y to the minimum possible Y newCenter.setY(m_selRect.height()/2); } else if(newCenter.y() >= QApplication::desktop()->height()-m_selRect.height()/2) { // set Y to the maximum possible Y newCenter.setY(QApplication::desktop()->height()-m_selRect.height()/2-1); } // move to the new center m_selRect.moveCenter(newCenter); // update the grab rectangle display m_selRect.update(); grabFrame(); } else if(m_mouseMode == GrabSelection) { QPoint newPos; // get new position newPos = e->globalPos(); QPoint delta = (newPos - m_oldMousePos)/m_zoom; QPoint newCenter = m_oldCenter-delta; // make sure the mouse position is not taking the grab window outside // the display if(newCenter.x() < m_selRect.width()/2) { // set X to the minimum possible X newCenter.setX(m_selRect.width()/2); } else if(newCenter.x() >= QApplication::desktop()->width()-m_selRect.width()/2) { // set X to the maximum possible X newCenter.setX(QApplication::desktop()->width()-m_selRect.width()/2-1); } if(newCenter.y() < m_selRect.height()/2) { // set Y to the minimum possible Y newCenter.setY(m_selRect.height()/2); } else if(newCenter.y() >= QApplication::desktop()->height()-m_selRect.height()/2) { // set Y to the maximum possible Y newCenter.setY(QApplication::desktop()->height()-m_selRect.height()/2-1); } // move to the new center m_selRect.moveCenter(newCenter); // update the grab rectangle display m_selRect.update(); grabFrame(); } } void KMagZoomView::keyPressEvent(QKeyEvent *e) { int offset = 16; if (e->modifiers() & Qt::ShiftModifier) offset = 1; if (e->key() == Qt::Key_Control) m_ctrlKeyPressed = true; else if (e->key() == Qt::Key_Shift) m_shiftKeyPressed = true; else if (e->key() == Qt::Key_Left) { if (e->modifiers() & Qt::ControlModifier) { if (offset >= m_selRect.width()) m_selRect.setWidth (1); else m_selRect.setWidth (m_selRect.width()-offset); } else if (contentsX() > 0) { offset = (int)(offset*m_zoom); if (contentsX() > offset) setContentsPos (contentsX()-offset, contentsY()); else setContentsPos (0, contentsY()); } else if (m_followMouse == false) { if (offset > m_selRect.x()) m_selRect.setX (0); else m_selRect.translate (-offset,0); } m_selRect.update(); } else if (e->key() == Qt::Key_Right) { if (e->modifiers() & Qt::ControlModifier) { if (m_selRect.right()+offset >= QApplication::desktop()->width()) m_selRect.setRight (QApplication::desktop()->width()-1); else m_selRect.setRight (m_selRect.right()+offset); } else if (contentsX() < contentsWidth()-visibleWidth()) { offset = (int)(offset*m_zoom); if (contentsX()+offset < contentsWidth()-visibleWidth()) setContentsPos (contentsX()+offset, contentsY()); else setContentsPos (contentsWidth()-visibleWidth(), contentsY()); } else if (m_followMouse == false) { if (m_selRect.right()+offset >= QApplication::desktop()->width()) m_selRect.moveTopRight (QPoint (QApplication::desktop()->width()-1, m_selRect.top())); else m_selRect.translate (offset,0); } m_selRect.update(); } else if (e->key() == Qt::Key_Up) { if (e->modifiers() & Qt::ControlModifier) { if (offset >= m_selRect.height()) m_selRect.setHeight (1); else m_selRect.setHeight (m_selRect.height()-offset); } else if (contentsY() > 0) { offset = (int)(offset*m_zoom); if (contentsY() > offset) setContentsPos (contentsX(), contentsY()-offset); else setContentsPos (contentsX(), 0); } else if (m_followMouse == false) { if (offset > m_selRect.y()) m_selRect.setY (0); else m_selRect.translate (0, -offset); } m_selRect.update(); } else if (e->key() == Qt::Key_Down) { if (e->modifiers() & Qt::ControlModifier) { if (m_selRect.bottom()+offset >= QApplication::desktop()->height()) m_selRect.setBottom (QApplication::desktop()->height()-1); else m_selRect.setBottom (m_selRect.bottom()+offset); } else if (contentsY() < contentsHeight()-visibleHeight()) { offset = (int)(offset*m_zoom); if (contentsY()+offset < contentsHeight()-visibleHeight()) setContentsPos (contentsX(), contentsY()+offset); else setContentsPos (contentsX(), contentsHeight()-visibleHeight()); } else if (m_followMouse == false) { if (m_selRect.bottom()+offset >= QApplication::desktop()->height()) m_selRect.moveBottomLeft (QPoint (m_selRect.left(), QApplication::desktop()->height()-1)); else m_selRect.translate (0, offset); } m_selRect.update(); } else e->ignore(); } void KMagZoomView::keyReleaseEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Control) m_ctrlKeyPressed = false; else if (e->key() == Qt::Key_Shift) m_shiftKeyPressed = false; else e->ignore(); } void KMagZoomView::focusOutEvent(QFocusEvent *e) { if(e->lostFocus() == true) { m_ctrlKeyPressed = false; m_shiftKeyPressed = false; } } // SLOTS /** * This will fit the zoom view to the view window, thus using the maximum * possible space in the window. */ void KMagZoomView::fitToWindow() { unsigned int newWidth, newHeight; // this is a temporary solution, cast, maybe newWidth and newHeight should be float if ((m_rotation == 90) || (m_rotation == 270)) { newWidth = static_cast((visibleHeight() + m_zoom - 1) / m_zoom); newHeight = static_cast((visibleWidth() + m_zoom - 1) / m_zoom); } else { newWidth = static_cast((visibleWidth() + m_zoom - 1) / m_zoom); newHeight = static_cast((visibleHeight() + m_zoom - 1) / m_zoom); } QPoint currCenter = m_selRect.center(); m_selRect.setWidth(newWidth); m_selRect.setHeight(newHeight); // make sure the selection window does not go outside of the display if(currCenter.x() < m_selRect.width()/2) { // set X to the minimum possible X currCenter.setX(m_selRect.width()/2); } else if(currCenter.x() >= QApplication::desktop()->width()-m_selRect.width()/2) { // set X to the maximum possible X currCenter.setX(QApplication::desktop()->width()-m_selRect.width()/2-1); } if(currCenter.y() < m_selRect.height()/2) { // set Y to the minimum possible Y currCenter.setY(m_selRect.height()/2); } else if(currCenter.y() >= QApplication::desktop()->height()-m_selRect.height()/2) { // set Y to the maximum possible Y currCenter.setY(QApplication::desktop()->height()-m_selRect.height()/2-1); } m_selRect.moveCenter(currCenter); // update the grab rectangle display m_selRect.update(); // m_fitToWindow = true; viewport()->update(); } void KMagZoomView::setFitToWindow(bool fit) { m_fitToWindow = fit; if (fit) fitToWindow(); } /** * Grabs frame from X */ void KMagZoomView::grabFrame() { // check refresh status if (!m_refreshSwitch) return; // check if follow-mouse or follow-focus are enabled if((m_followMouse || m_followFocus) && (m_mouseMode != ResizeSelection)) { // center-position of the grab-area QPoint newCenter; if(m_followMouse) { // set new center to be the current mouse position newCenter = QCursor::pos(); #ifdef QAccessibilityClient_FOUND } else if(m_followFocus) { // set the new center to the current keyboard cursor position newCenter = m_oldFocus; if(m_followBoth) { m_followFocus=false; m_followMouse=true; } #endif } // make sure the mouse position is not taking the grab window outside // the display if(newCenter.x() < m_selRect.width()/2) { // set X to the minimum possible X newCenter.setX(m_selRect.width()/2); } else if(newCenter.x() >= QApplication::desktop()->width()-m_selRect.width()/2) { // set X to the maximum possible X newCenter.setX(QApplication::desktop()->width()-m_selRect.width()/2-1); } if(newCenter.y() < m_selRect.height()/2) { // set Y to the minimum possible Y newCenter.setY(m_selRect.height()/2); } else if(newCenter.y() >= QApplication::desktop()->height()-m_selRect.height()/2) { // set Y to the maximum possible Y newCenter.setY(QApplication::desktop()->height()-m_selRect.height()/2-1); } // move to the new center m_selRect.moveCenter(newCenter); // update the grab rectangle display m_selRect.update(); } // define a normalized rectangle QRect selRect = m_selRect.normalized(); // grab screenshot from the screen and put it in the pixmap m_coloredPixmap = QPixmap::grabWindow(QApplication::desktop()->winId(), selRect.x(), selRect.y(), selRect.width(), selRect.height()); // colorize the grabbed pixmap if (m_colormode != 0) m_coloredPixmap = QPixmap::fromImage(ColorSim::recolor(m_coloredPixmap.toImage(), m_colormode)); // erase background covered by kmag view ... QRect viewRect = rect(); viewRect.translate(mapTo(window(), QPoint(0, 0))); viewRect.translate(-selRect.topLeft()); viewRect.translate(window()->geometry().topLeft()); QRegion region(viewRect); // ... but exclude own popups ... const QList siblings = QApplication::topLevelWidgets(); foreach (QWidget *sibling, siblings) { if (sibling != window() && (sibling->windowType() & Qt::Window) && sibling->isVisible()) { QRect rect = sibling->frameGeometry(); rect.translate(-selRect.topLeft()); region -= rect; } } QPainter p(&m_coloredPixmap); foreach (const QRect &rect, region.rects()) { p.fillRect(rect, palette().dark()); } p.end(); QRect r = m_zoomMatrix.mapRect(m_coloredPixmap.rect()); // call repaint to display the newly grabbed image horizontalScrollBar()->setPageStep(r.width()); verticalScrollBar()->setPageStep(r.height()); viewport()->update(); } /** * Updates the mouse cursor in the zoom view. */ void KMagZoomView::updateMouseView() { if (m_fps < 8) viewport()->update(); } /** * Toggles the state of refreshing. */ void KMagZoomView::toggleRefresh() { if(m_refreshSwitch) { m_refreshSwitch = false; m_grabTimer.stop(); m_mouseViewTimer.stop(); } else { m_refreshSwitch = true; m_grabTimer.start(1000/m_fps); m_mouseViewTimer.start(40); } } /** * This function sets the zoom value to be used. */ void KMagZoomView::setZoom(float zoom) { // use this zoom m_zoom = zoom; // update selection window size when zooming in if necessary if (m_fitToWindow) fitToWindow(); // recompute the zoom matrix setupMatrix(); viewport()->update(); } /** * This function sets the rotation value to be used. */ void KMagZoomView::setRotation(int rotation) { // use this rotation m_rotation = rotation; // update selection window size if necessary if (m_fitToWindow) fitToWindow(); // recompute the zoom matrix setupMatrix(); viewport()->update(); } /** * Set a new color simulation mode. */ void KMagZoomView::setColorMode(int mode) { if (m_colormode != mode) { m_colormode = mode; viewport()->update(); } } /** * Set a new refresh rate. */ void KMagZoomView::setRefreshRate(float fps) { if(fps < 0.1) return; m_fps = static_cast(fps); if(m_grabTimer.isActive()) m_grabTimer.start(static_cast(1000.0/m_fps)); } void KMagZoomView::showSelRect(bool show) { m_selRect.alwaysVisible(show); if(show) { m_selRect.show(); } else if(m_mouseMode == Normal) { m_selRect.hide(); } } /** * Sets the selection rectangle to the given position. */ void KMagZoomView::setSelRectPos(const QRect & rect) { m_selRect.setRect(rect.x(), rect.y(), rect.width(), rect.height()); m_selRect.update(); grabFrame(); } bool KMagZoomView::showMouse(unsigned int type) { if(int(type) > m_showMouseTypes.count()-1) return (false); else m_showMouse = type; return(true); } unsigned int KMagZoomView::getShowMouseType() const { return (m_showMouse); } QStringList KMagZoomView::getShowMouseStringList() const { return (m_showMouseTypes); } /** * Returns the image which is being displayed. It's again drawn by adding * the mouse cursor if needed. */ QImage KMagZoomView::getImage() { QImage image = m_coloredPixmap.transformed(m_zoomMatrix).toImage(); // show the pixel under mouse cursor if(m_showMouse && !image.isNull()) { // paint the mouse cursor w/o updating to a newer position paintMouseCursor(&image, calcMousePos(false)); } return(image); } diff --git a/kmagzoomview.h b/kmagzoomview.h index c6dcb4d..a1d86f5 100644 --- a/kmagzoomview.h +++ b/kmagzoomview.h @@ -1,291 +1,291 @@ /*************************************************************************** kmagview.h - description ------------------- begin : Mon Feb 12 23:45:41 EST 2001 copyright : (C) 2001-2003 by Sarang Lakare email : sarang#users.sf.net copyright : (C) 2003-2004 by Olaf Schmidt email : ojschmidt@kde.org copyright : (C) 2008 by Matthew Woehlke email : mw_triad@users.sourceforge.net copyright (C) 2010 Sebastian Sauer email sebsauer@kdab.com ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef KMagZoomView_h #define KMagZoomView_h // include files for Qt -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //class KMagSelRect; #include "kmagselrect.h" #include "focustrackconfig.h" #ifdef QAccessibilityClient_FOUND #include #endif /** * The KMagZoomView class provides the view widget for the KmagApp instance. * * @author Sarang Lakare */ class KMagZoomView : public QAbstractScrollArea { Q_OBJECT public: /// Constructor for the main view explicit KMagZoomView(QWidget *parent = 0, const char *name=0); /// Destructor for the main view ~KMagZoomView(); /// Toggles the refreshing of the window void toggleRefresh(); /// Returns the currently displayed zoomed view QImage getImage(); /// Returns the state of the refresh switch bool getRefreshStatus() const { return m_refreshSwitch; } /// Returns the status of followMouse bool getFollowMouse() const { return m_followMouse; } #ifdef QAccessibilityClient_FOUND /// Returns the status of followFocus bool getFollowFocus() const { return m_followFocus; } #endif /// Get the status of "show rect. always" bool getShowSelRect() const { return (m_selRect.getAlwaysVisible()); } /// Get the coordinates of the selection rectangle QRect getSelRectPos() const { return static_cast(m_selRect); } /// Returns the current state of show mouse unsigned int getShowMouseType() const; /// Returns the different ways of showing mouse cursor QStringList getShowMouseStringList() const; /// Returns the status of "fit to window" option bool getFitToWindow() const { return (m_fitToWindow); } public slots: /// Sets zoom to the given value void setZoom(float zoom = 0.0); /// Sets the rotation to the given value void setRotation(int rotation = 0); /// Sets the color mode to the given value void setColorMode(int mode = 0); /// Grabs a frame from the given portion of the display void grabFrame(); /// Update the mouse cursor in the zoom view void updateMouseView(); /// Set grab-window-follows-mouse mode void followMouse(bool follow = true); #ifdef QAccessibilityClient_FOUND /// Set grab-window-follows-mouse-and-keyboard-focus mode void followBoth(bool follow = true); /// Set grab-window-follows-keyboard-focus mode void followFocus(bool follow = true); #endif /// Shows/Hides the selection marker void showSelRect(bool show=true); /// Set the position of the selection region to the given pos void setSelRectPos(const QRect & rect); /// Set the refresh rate in fps (frames per second) void setRefreshRate(float fps); /// Shows/Hides mouse cursor in the zoomed view bool showMouse(unsigned int type); /// Set the status of "fit to window" option void setFitToWindow (bool fit=true); /// Fits the zoom view to the zoom view window void fitToWindow(); #ifdef QAccessibilityClient_FOUND private slots: /// Called from a dbus service when followFocus is true void focusChanged(const QAccessibleClient::AccessibleObject &object); #endif protected: /// Called when the widget is hidden void hideEvent( QHideEvent * e); /// Called when the widget is shown void showEvent( QShowEvent * e); /// Called when the widget has been resized void resizeEvent(QResizeEvent *e); /// Called when the widget is to be repainted void paintEvent(QPaintEvent *e); /// This function calculates the mouse position relative to the image QPoint calcMousePos(bool updateMousePos=true); /// This function draws the mouse cursor void paintMouseCursor(QPaintDevice *dev, const QPoint & mousePos); /// Called when mouse click is detected void mousePressEvent (QMouseEvent *e); /// Called when mouse is moved void mouseMoveEvent(QMouseEvent *e); /// Mouse button release event handler void mouseReleaseEvent(QMouseEvent *e); /// Mouse button release event handler void keyPressEvent(QKeyEvent *e); /// Mouse button release event handler void keyReleaseEvent(QKeyEvent *e); /// Mouse button release event handler void focusOutEvent(QFocusEvent *e); /// Returns the rectangle where the pixmap will be drawn QRect pixmapRect(); /// Q3ScrollView porting helpers, maybe inline them int contentsX() const; int contentsY() const; int contentsWidth() const; int contentsHeight() const; int visibleWidth() const; int visibleHeight() const; void setContentsPos(int x, int y); /// Setup transformation matrix for zooming, rotating, and mirroring void setupMatrix(); private: #ifdef QAccessibilityClient_FOUND /// Global Accessibility Registry QAccessibleClient::Registry m_registry; #endif /// Stores the pixmap which is recolored from the grabbed one QPixmap m_coloredPixmap; /// The selected rectangle which is to be grabbed KMagSelRect m_selRect; /// Grabs a window when the timer goes off QTimer m_grabTimer; /// Updates the mouse view QTimer m_mouseViewTimer; /// Zoom matrix QMatrix m_zoomMatrix; /// Saves the mouse position when a button is clicked and b4 the cursor is moved to new position QPoint m_oldMousePos; /// Saves the center of the grab window QPoint m_oldCenter; #ifdef QAccessibilityClient_FOUND /// Saves the keyboard focus position QPoint m_oldFocus; #endif /// Possible modes for the mouse to be in enum KMagMouseMode { Normal, StartSelect, ResizeSelection, MoveSelection, GrabSelection }; /// The current mode which the mouse is KMagMouseMode m_mouseMode; /// stores the state of the Ctrl key bool m_ctrlKeyPressed; /// stores the state of the Shift key bool m_shiftKeyPressed; /// Store the more recent updated cursor position QPoint m_latestCursorPos; /// Various ways of showing mouse cursor QStringList m_showMouseTypes; // configuration options: /// To follow mouse motion or not when no key is pressed bool m_followMouse; /// To follow keyboard focus or not bool m_followFocus; bool m_followBoth; /// State of refreshing - on or off bool m_refreshSwitch; /// Stores the state of the refresh switch on hide event bool m_refreshSwitchStateOnHide; /// Show mouse cursor type - 0 : do not show, non zero: show unsigned int m_showMouse; /// Frames per second for refresh unsigned int m_fps; /// Stores the amount to zoom the pixmap float m_zoom; /// Stores the degrees to rotate the pixmap int m_rotation; /// Stores color simulation mode to apply int m_colormode; /// Fit the zoom view to the zoom window bool m_fitToWindow; }; #endif // KMagZoomView_h diff --git a/main.cpp b/main.cpp index 3469742..cd5a590 100644 --- a/main.cpp +++ b/main.cpp @@ -1,79 +1,79 @@ /*************************************************************************** main.cpp - description ------------------- begin : Mon Feb 12 23:45:41 EST 2001 copyright : (C) 2001-2003 by Sarang Lakare email : sarang#users.sf.net ***************************************************************************/ /*************************************************************************** * * * 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 -#include +#include #include #include #include #include #include "kmag.h" #include "version.h" KmagApp *kmagapp; // Not needed, not used. //static const char description[] = // I18N_NOOP("Kmag"); // INSERT A DESCRIPTION FOR YOUR APPLICATION HERE int main(int argc, char *argv[]) { // about the application - KAboutData *aboutData = new KAboutData("kmag", 0, ki18n("KMagnifier"), KMAG_VERSION, + K4AboutData *aboutData = new K4AboutData("kmag", 0, ki18n("KMagnifier"), KMAG_VERSION, ki18n("Screen magnifier for the K Desktop Environment (KDE)"), - KAboutData::License_GPL, + K4AboutData::License_GPL, ki18n("Copyright 2001-2003 Sarang Lakare\nCopyright 2003-2004 Olaf Schmidt\nCopyright 2008 Matthew Woehlke"), KLocalizedString(), "http://accessibility.kde.org/"); // about the authors aboutData->addAuthor(ki18n("Sarang Lakare"), ki18n("Rewrite"),"sarang@users.sf.net", "http://www.cs.sunysb.edu/~lsarang/linux"); aboutData->addAuthor(ki18n("Michael Forster"), ki18n("Original idea and author (KDE1)"), "forster@fmi.uni-passau.de"); aboutData->addAuthor(ki18n("Olaf Schmidt"), ki18n("Rework of the user interface, improved selection window, speed optimization, rotation, bug fixes"), "ojschmidt@kde.org"); aboutData->addCredit(ki18n("Matthew Woehlke"), ki18n("Color-blindness simulation"), "mw_triad@users.sourceforge.net"); aboutData->addCredit(ki18n("Sebastian Sauer"), ki18n("Focus tracking"), "sebsauer@kdab.com"); aboutData->addCredit(ki18n("Claudiu Costin"), ki18n("Some tips"), "claudiuc@work.ro", "http://www.ro.kde.org"); KCmdLineArgs::init( argc, argv, aboutData ); KCmdLineOptions options; options.add("+[File]", ki18n("File to open")); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app; if (app.isSessionRestored()) { RESTORE(KmagApp); } else { kmagapp = new KmagApp(); kmagapp->show(); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); args->clear(); } return app.exec(); }