Index: trunk/kdeaccessibility/kmag/kmag.cpp =================================================================== --- trunk/kdeaccessibility/kmag/kmag.cpp (revision 123086) +++ trunk/kdeaccessibility/kmag/kmag.cpp (revision 123087) @@ -1,416 +1,420 @@ //$Id$ /*************************************************************************** kmag.cpp - description ------------------- begin : Mon Feb 12 23:45:41 EST 2001 copyright : (C) 2001 by Sarang Lakare email : sarang@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. * * * ***************************************************************************/ #include // include files for QT #include #include #include #include #include #include #include // include files for KDE #include #include #include #include #include #include #include #include #include #include #include #if KDE_VERSION < 220 #include #else #include #endif // application specific includes #include "kmag.moc" #include "kmagzoomview.h" #include "kmagselrect.h" #define ID_STATUS_MSG 1 KmagApp::KmagApp(QWidget* , const char* name) : KMainWindow(0, name, WStyle_MinMax | WType_TopLevel | WDestructiveClose | WStyle_ContextHelp | WStyle_StaysOnTop) { config=kapp->config(); zoomArrayString << "[5:1] 20%" << "[2:1] 50%" << "[1.33:1] 75%" << "[1:1] 100%" << "[1:1.25] 125%" << "[1:1.5] 150%" << "[1:2] 200%" << "[1:3] 300%" << "[1:4] 400%" << "[1:5] 500%" << "[1:6] 600%" << "[1:7] 700%" << "[1:8] 800%" << "[1:12] 1200%" << "[1:16] 1600%" << "[1:20] 2000%"; // Is there a better way to initialize a vector array? zoomArray.push_back(0.2); zoomArray.push_back(0.5); zoomArray.push_back(0.75); zoomArray.push_back(1.0); zoomArray.push_back(1.25); zoomArray.push_back(1.5); zoomArray.push_back(2.0); zoomArray.push_back(3.0); zoomArray.push_back(4.0); zoomArray.push_back(5.0); zoomArray.push_back(6.0); zoomArray.push_back(7.0); zoomArray.push_back(8.0); zoomArray.push_back(12.0); zoomArray.push_back(16.0); zoomArray.push_back(20.0); if(zoomArrayString.count() != zoomArray.size()) { cerr << "Check the zoom array in the constructor." << endl; exit(1); } // call inits to invoke all other construction parts initView(); initActions(); initConnections(); // read options from config file readOptions(); // Register all KIO image formats - to be used when saving image. KImageIO::registerFormats(); } /** * Default destructor. */ KmagApp::~KmagApp() { } void KmagApp::initActions() { fileNewWindow = new KAction(i18n("New &Window"), 0, 0, this, SLOT(slotFileNewWindow()), actionCollection(),"file_new_window"); refreshSwitch = KStdAction::zoom(this, SLOT(slotToggleRefresh()), actionCollection()); refreshSwitch->setIcon("stop.png"); refreshSwitch->setText(i18n("Stop Update")); 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 = new KAction(i18n("&SnapShot"), "ksnapshot", Key_F2, this, SLOT(saveZoomPixmap()), actionCollection(),"snapshot"); m_pSnapshot->setWhatsThis(i18n("Click to save the image being displayed to a file.")); m_pSnapshot->setToolTip(i18n("Save image to a file.")); m_pPrint = KStdAction::print(this, SLOT(slotFilePrint()), actionCollection(), "print"); m_pPrint->setWhatsThis(i18n("Click on this button to print the current zommed image.")); m_pZoomIn = KStdAction::zoomIn(this, SLOT(zoomIn()), actionCollection(), "zoom_in"); m_pZoomIn->setWhatsThis(i18n("Click on this button to zoom-in on the selected region.")); m_pZoomBox = new KSelectAction(i18n("&Zoom"),0,actionCollection(),"zoom"); m_pZoomBox->setItems(zoomArrayString); m_pZoomBox->setComboWidth(50); m_pZoomOut = KStdAction::zoomOut(this, SLOT(zoomOut()), actionCollection(), "zoom_out"); m_pZoomOut->setWhatsThis(i18n("Click on this button to zoom-out on the selected region.")); KToolBarPopupAction *helpAction = new KToolBarPopupAction(i18n("&Help"), "help", 0, actionCollection(), "help"); KHelpMenu *newHelpMenu = new KHelpMenu(this, KGlobal::instance()->aboutData()); helpAction->setDelayed(false); KAction *action = KStdAction::helpContents(newHelpMenu, SLOT(appHelpActivated()), actionCollection()); action->plug(helpAction->popupMenu()); action = KStdAction::reportBug(newHelpMenu, SLOT(reportBug()), actionCollection()); action->plug(helpAction->popupMenu()); action = KStdAction::aboutApp(newHelpMenu, SLOT(aboutApplication()), actionCollection()); action->plug(helpAction->popupMenu()); action = KStdAction::aboutKDE(newHelpMenu, SLOT(aboutKDE()), actionCollection()); action->plug(helpAction->popupMenu()); // plug things into the toolbar refreshSwitch->plug(toolBar()); m_pZoomIn->plug(toolBar()); m_pZoomBox->plug(toolBar()); m_pZoomOut->plug(toolBar()); m_pPrint->plug(toolBar()); m_pSnapshot->plug(toolBar()); helpAction->plug(toolBar()); } void KmagApp::initView() { QVBox *mainView = new QVBox(this); m_zoomView = new KMagZoomView( mainView, "ZoomView" ); m_zoomView->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, m_zoomView->sizePolicy().hasHeightForWidth() ) ); m_zoomView->setMouseTracking(true); m_zoomView->setFrameShape( QFrame::StyledPanel ); m_zoomView->setFrameShadow( QFrame::Raised ); m_settingsGroup = new QButtonGroup( mainView, "m_settingsGroup" ); m_settingsGroup->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, m_settingsGroup->sizePolicy().hasHeightForWidth() ) ); m_settingsGroup->setFrameShape( QButtonGroup::NoFrame ); m_settingsGroup->setTitle(""); m_settingsGroup->setColumnLayout(0, Qt::Vertical ); m_settingsGroup->layout()->setSpacing( 0 ); m_settingsGroup->layout()->setMargin( 0 ); QHBoxLayout *settingsGroupLayout = new QHBoxLayout( m_settingsGroup->layout() ); settingsGroupLayout->setAlignment( Qt::AlignTop ); settingsGroupLayout->setSpacing( 6 ); settingsGroupLayout->setMargin( 0 ); m_followMouseButton = new QCheckBox( m_settingsGroup, "m_followMouseButton" ); m_followMouseButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, m_followMouseButton->sizePolicy().hasHeightForWidth() ) ); m_followMouseButton->setText( i18n( "Follow Mouse" ) ); settingsGroupLayout->addWidget( m_followMouseButton ); connect(m_followMouseButton, SIGNAL(toggled(bool)), m_zoomView, SLOT(followMouse(bool))); m_showSelRectButton = new QCheckBox( m_settingsGroup, "m_showSelRectButton" ); m_showSelRectButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, m_showSelRectButton->sizePolicy().hasHeightForWidth() ) ); m_showSelRectButton->setText( i18n( "Show Selected Area" ) ); settingsGroupLayout->addWidget( m_showSelRectButton ); connect(m_showSelRectButton, SIGNAL(toggled(bool)), m_zoomView, SLOT(showSelRect(bool))); setCentralWidget(mainView); } void KmagApp::initConnections() { // change in zoom value -> update the view connect(this, SIGNAL(updateZoomValue(float)), m_zoomView, SLOT(setZoom(float))); // change in zoom index -> update the selector connect(this, SIGNAL(updateZoomIndex(int)), m_pZoomBox, SLOT(setCurrentItem(int))); // selector selects a zoom index -> set the zoom index connect(m_pZoomBox, SIGNAL(activated(int)), this, SLOT(setZoomIndex(int))); } void KmagApp::saveOptions() { config->setGroup("General Options"); config->writeEntry("Geometry", size()); config->writeEntry("ZoomIndex", m_zoomIndex); config->writeEntry("FollowMouse", m_zoomView->getFollowMouse()); + config->writeEntry("SelRect", m_zoomView->getSelRectPos()); toolBar("mainToolBar")->saveSettings(config,"Main ToolBar"); } void KmagApp::readOptions() { config->setGroup("General Options"); QSize size=config->readSizeEntry("Geometry"); if(!size.isEmpty()) { resize(size); } // set zoom - defaults to 2x unsigned int zoomIndex = config->readUnsignedNumEntry("ZoomIndex", 7); setZoomIndex(zoomIndex); emit updateZoomIndex(m_zoomIndex); bool followMouse = config->readBoolEntry("FollowMouse", false); m_zoomView->followMouse(followMouse); m_followMouseButton->setChecked(followMouse); + QRect defaultRect(0, 0, 128, 128); + m_zoomView->setSelRectPos(config->readRectEntry("SelRect", &defaultRect)); + toolBar("mainToolBar")->applySettings(config,"Main ToolBar"); } bool KmagApp::queryClose() { return (true); } bool KmagApp::queryExit() { saveOptions(); return true; } ///////////////////////////////////////////////////////////////////// // SLOT IMPLEMENTATION ///////////////////////////////////////////////////////////////////// /** * 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 cerr << "Invalid index!" << endl; 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[m_zoomIndex]); } /** * 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::null, KImageIO::pattern(KImageIO::Writing), 0,i18n("Save zoomed region")); if(!url.filename().isEmpty()) { m_zoomView->getPixmap().save(url.fileName(), KImageIO::type(url.fileName()).latin1()); } if(toggled) { slotToggleRefresh(); } } void KmagApp::slotToggleRefresh() { m_zoomView->toggleRefresh(); if(m_zoomView->getRefreshStatus()) { refreshSwitch->setIcon("stop.png"); refreshSwitch->setText(i18n("Stop Update")); refreshSwitch->setToolTip(i18n("Click to stop window update")); } else { refreshSwitch->setIcon("reload.png"); refreshSwitch->setText(i18n("Start Update")); refreshSwitch->setToolTip(i18n("Click to start window update")); } } void KmagApp::slotFileNewWindow() { KmagApp *new_window= new KmagApp(); new_window->show(); } void KmagApp::slotFilePrint() { #ifndef QT_NO_PRINTER bool toggled(false); #if KDE_VERSION < 220 QPrinter printer; #else KPrinter printer; #endif // stop refresh temporarily if (m_zoomView->getRefreshStatus()) { slotToggleRefresh(); toggled = true; } printer.setFullPage(true); if (printer.setup(this)) { QPainter paint; if(!paint.begin(&printer)) return; // draw the pixmap paint.drawPixmap(0, 0, m_zoomView->getPixmap()); // end the painting paint.end(); } if(toggled) { slotToggleRefresh(); } #endif // QT_NO_PRINTER } void KmagApp::slotEditCopy() { } void KmagApp::slotViewToolBar() { /////////////////////////////////////////////////////////////////// // turn Toolbar on or off if(!viewToolBar->isChecked()) { toolBar("mainToolBar")->hide(); } else { toolBar("mainToolBar")->show(); } } Index: trunk/kdeaccessibility/kmag/kmagzoomview.cpp =================================================================== --- trunk/kdeaccessibility/kmag/kmagzoomview.cpp (revision 123086) +++ trunk/kdeaccessibility/kmag/kmagzoomview.cpp (revision 123087) @@ -1,522 +1,530 @@ //$Id$ /*************************************************************************** kmagview.cpp - description ------------------- begin : Mon Feb 12 23:45:41 EST 2001 copyright : (C) 2001 by Sarang Lakare email : sarang@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. * * * ***************************************************************************/ #include #include #include // application specific includes //#include "kmagdoc.h" #include "kmag.h" #include "kmagselrect.moc" #include "kmagzoomview.h" // include files for Qt -//#include #include #include KMagZoomView::KMagZoomView(QWidget *parent, const char *name) : QFrame(parent, name), m_selRect(0, 0, 128, 128), m_grabTimer(parent), m_zoom(1.0), m_followMouse(false) { setFrameStyle(QFrame::WinPanel | QFrame::Sunken); setLineWidth(0); setBackgroundColor(QColor("white")); setFocusPolicy(QWidget::StrongFocus); // init the zoom matrix m_zoomMatrix.reset(); m_zoomMatrix.scale(m_zoom, m_zoom); // update freq m_fps = 10; m_ctrlKeyPressed = false; m_shiftKeyPressed = false; m_refreshSwitch = true; // start the grabTimer and connect it to grabFrame() m_grabTimer.start(1000/m_fps); connect(&m_grabTimer, SIGNAL(timeout()), SLOT(grabFrame())); QWhatsThis::add(this, i18n("This is the main window which shows the contents of the\ selected region. The contents will be magnified if zoom level is set.")); } KMagZoomView::~KMagZoomView() { } /** * This function will set/reset mouse following of grab window. */ void KMagZoomView::followMouse(bool follow) { if(follow) { m_followMouse = true; setMouseTracking(true); m_mouseMode = Normal; } else { m_followMouse = false; setMouseTracking(false); m_mouseMode = Normal; } } /** * Called when the widget is to be repainted * * @param p */ void KMagZoomView::paintEvent(QPaintEvent *e) { // get a rectangle centered inside the frame QRect pRect(pixmapRect()); QRect uRect(e->rect()); // get the rectangle in the frame QRect wRect(contentsRect()); QPainter p(this); p.setClipRect(wRect); QRect r; // top r = wRect; r.setBottom(pRect.top()-1); r = r.intersect(uRect); if ( !r.isEmpty() ) p.eraseRect(r); // bottom r = wRect; r.setTop(pRect.bottom()+1); r = r.intersect(uRect); if ( !r.isEmpty() ) p.eraseRect(r); // left r = wRect; r.setTop(pRect.top()); r.setBottom(pRect.bottom()); r.setRight(pRect.left()-1); r = r.intersect(uRect); if ( !r.isEmpty() ) p.eraseRect(r); // right r = wRect; r.setTop(pRect.top()); r.setBottom(pRect.bottom()); r.setLeft(pRect.right()+1); r = r.intersect(uRect); if ( !r.isEmpty() ) p.eraseRect(r); // draw the pixmap p.drawPixmap(pRect.x(), pRect.y(), m_grabbedZoomedPixmap); // bitBlt(this, 0, 0, &m_grabbedZoomedPixmap); } QRect KMagZoomView::pixmapRect() { int free_x = width() - m_grabbedZoomedPixmap.width(); int free_y = height() - m_grabbedZoomedPixmap.height(); QPoint startPoint((free_x > 0) ? (free_x / 2) : 0, (free_y > 0) ? (free_y / 2) : 0); QRect r(m_grabbedZoomedPixmap.rect()); r.moveTopLeft(startPoint); return (r); } // MOUSE ACTIONS /** * Called when mouse is clicked inside the window * * @param e */ void KMagZoomView::mousePressEvent(QMouseEvent *e) { // don't do anything if follow mouse is enabled if(m_followMouse) return; switch(e->button()) { case QMouseEvent::LeftButton : if(m_ctrlKeyPressed) { // check if currently in resize mode if(m_mouseMode != ResizeSelection) { // set the mode to ResizeSelection m_mouseMode = ResizeSelection; // set mouse cursor to "resize all direction" setCursor(sizeAllCursor); // 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.bottomRight()); // show the selection rectangle m_selRect.show(); } } else if(m_shiftKeyPressed) { // check if currently in move mode if(m_mouseMode != MoveSelection) { m_mouseMode = MoveSelection; // set mouse cursor to cross hair setCursor(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 { // check if currently in move mode if(m_mouseMode != GrabSelection) { m_mouseMode = GrabSelection; // set mouse cursor to hand setCursor(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(); } } break; case QMouseEvent::MidButton : break; case QMouseEvent::RightButton : break; case QMouseEvent::NoButton : break; // do nothing default: ; } } /** * Called when a mouse button is released * * @param e */ void KMagZoomView::mouseReleaseEvent(QMouseEvent *e) { // don't do anything if follow mouse is enabled if(m_followMouse) return; switch(e->button()) { case QMouseEvent::LeftButton : // 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(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(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(arrowCursor); } break; case QMouseEvent::MidButton : break; case QMouseEvent::RightButton : break; case QMouseEvent::NoButton : break; // do nothing default: ; } } /** * Called when mouse is moved inside the window * * @param e */ void KMagZoomView::mouseMoveEvent(QMouseEvent *e) { // don't do anything if follow mouse is enabled if(m_followMouse) return; 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(); } 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.width()/2) { // set Y to the maximum possible Y newCenter.setY(QApplication::desktop()->height()-m_selRect.width()/2-1); } // move to the new center m_selRect.moveCenter(newCenter); // update the grab rectangle display m_selRect.update(); } 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.width()/2) { // set Y to the maximum possible Y newCenter.setY(QApplication::desktop()->height()-m_selRect.width()/2-1); } // move to the new center m_selRect.moveCenter(newCenter); // update the grab rectangle display m_selRect.update(); } } void KMagZoomView::keyPressEvent(QKeyEvent *e) { if(e->key() == QKeyEvent::Key_Control) { m_ctrlKeyPressed = true; } else if(e->key() == QKeyEvent::Key_Shift){ m_shiftKeyPressed = true; } else { e->ignore(); } } void KMagZoomView::keyReleaseEvent(QKeyEvent *e) { if(e->key() == QKeyEvent::Key_Control) { m_ctrlKeyPressed = false; } else if(e->key() == QKeyEvent::Key_Shift){ m_shiftKeyPressed = false; } else { e->ignore(); } } void KMagZoomView::focusOutEvent(QFocusEvent *e) { if(e->lostFocus() == TRUE) { m_ctrlKeyPressed = false; m_shiftKeyPressed = false; } } // SLOTS -/** Grabs frame from X - * +/** + * Grabs frame from X */ void KMagZoomView::grabFrame() { - // check if follow-mouse is enabled if(m_followMouse) { // in this case grab w.r.t the current mouse position QPoint newCenter; // set new center to be the current mouse position newCenter = m_cursor.pos(); // 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.width()/2) { // set Y to the maximum possible Y newCenter.setY(QApplication::desktop()->height()-m_selRect.width()/2-1); } // move to the new center m_selRect.moveCenter(newCenter); } //QRect r = pixmapRect(); // define a normalized rectangle QRect selRect = m_selRect.normalize(); // grab screenshot from the screen and put it in the pixmap m_grabbedPixmap = QPixmap::grabWindow(QApplication::desktop()->winId(), selRect.x(), selRect.y(), selRect.width(), selRect.height()); // zoom the image m_grabbedZoomedPixmap = m_grabbedPixmap.xForm(m_zoomMatrix); // call repaint to display the newly grabbed image repaint(pixmapRect(), false); // update the grab rectangle display m_selRect.update(); } -/** Toggles the state of refreshing. - * - */ +/** + * Toggles the state of refreshing. + */ void KMagZoomView::toggleRefresh() { if(m_refreshSwitch) { m_refreshSwitch = false; m_grabTimer.stop(); } else { m_refreshSwitch = true; m_grabTimer.start(1000/m_fps); } } /** * This function sets the zoom value to be used. */ void KMagZoomView::setZoom(float zoom) { // use this zoom m_zoom = zoom; // recompute the zoom matrix m_zoomMatrix.reset(); m_zoomMatrix.scale(m_zoom, m_zoom); m_grabbedZoomedPixmap = m_grabbedPixmap.xForm(m_zoomMatrix); repaint(); } 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(); +} Index: trunk/kdeaccessibility/kmag/kmagzoomview.h =================================================================== --- trunk/kdeaccessibility/kmag/kmagzoomview.h (revision 123086) +++ trunk/kdeaccessibility/kmag/kmagzoomview.h (revision 123087) @@ -1,170 +1,177 @@ //$Id$ /*************************************************************************** kmagview.h - description ------------------- begin : Mon Feb 12 23:45:41 EST 2001 copyright : (C) 2001 by Sarang Lakare email : sarang@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; version 2 of the License * * * ***************************************************************************/ #ifndef KMagZoomView_h_ #define KMagZoomView_h_ #ifdef HAVE_CONFIG_H #include #endif // include files for Qt #include #include #include #include #include #include #include //class KMagSelRect; #include "kmagselrect.h" /** The KMagZoomView class provides the view widget for the KmagApp instance. * The View instance inherits QWidget as a base class and represents the view object of a KTMainWindow. As KMagZoomView is part of the * docuement-view model, it needs a reference to the document object connected with it by the KmagApp class to manipulate and display * the document structure provided by the KmagDoc class. * * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team. * @version KDevelop version 0.4 code generation */ class KMagZoomView : public QFrame { Q_OBJECT public: /// Constructor for the main view KMagZoomView(QWidget *parent = 0, const char *name=0); /// Destructor for the main view ~KMagZoomView(); /// Return the current pixmap const QPixmap & getPixmap() const { return(m_grabbedZoomedPixmap); }; /// Returns the state of the refresh switch bool getRefreshStatus() const { return m_refreshSwitch; }; /// Returns teh status of followMouse bool getFollowMouse() const { return m_followMouse; }; + /// Get the status of "show rect. always" bool getShowSelRect() const { return m_showSelRect; }; + /// Get the coordinates of the selection rectangle + QRect getSelRectPos() const { return static_cast(m_selRect); }; + /// Toggles the refreshing of the window void toggleRefresh(); public slots: /// Sets zoom to the given value void setZoom(float zoom = 0.0); /// Grabs a frame from the given portion of the display void grabFrame(); /// Set grab-window-follows-mouse mode void followMouse(bool follow = true); /// 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); + protected: /// Called when the widget is to be repainted void paintEvent(QPaintEvent *p); /// 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(); private: /// Stores the pixmap grabbed from the screen - to be zoomed QPixmap m_grabbedPixmap; /// Stores the pixmap which is zoomed from the grabbed one - this will be actaully drawn QPixmap m_grabbedZoomedPixmap; /// Frames per second for refresh unsigned int m_fps; /// The selected rectangle which is to be grabbed KMagSelRect m_selRect; /// Grabs a window when the timer goes off QTimer m_grabTimer; /// Zoom matrix QWMatrix m_zoomMatrix; /// Stores the amount to zoom the pixmap float m_zoom; /// 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; /// State of refreshing - on or off bool m_refreshSwitch; /// 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; /// To follow mouse motion or not when no key is pressed bool m_followMouse; /// Always show the selection rectangle bool m_showSelRect; /// Use this to get global cursor position QCursor m_cursor; }; #endif // KMagZoomView_h_