bool KSnapshot::eventFilter( QObject* o, QEvent* e) { if ( o == grabber && e->type() == QEvent::MouseButtonPress ) { QMouseEvent* me = (QMouseEvent*) e; if ( QWidget::mouseGrabber() != grabber ) return false; if ( me->button() == LeftButton ) performGrab(); } return false; }
void KSnapshot::grabTimerDone() { if ( mainWidget->mode() == Region ) { rgnGrab = new RegionGrabber(); connect( rgnGrab, SIGNAL( regionGrabbed( const QPixmap & ) ), SLOT( slotRegionGrabbed( const QPixmap & ) ) ); } else { performGrab(); } KNotifyClient::beep(i18n("The screen has been successfully grabbed.")); }
void KSnapshot::grabTimerDone() { if ( mode() == Region ) { grabRegion(); } else if ( mode() == FreeRegion ) { grabFreeRegion(); } else { performGrab(); } //KNotification::beep(i18n("The screen has been successfully grabbed.")); }
void KSnapshot::grabTimerDone() { performGrab(); KNotifyClient::beep(i18n("The screen has been successfully grabbed.")); }
void grabPointer(AppInfo *app) { performGrab(app, GRAB_POINTER, "pointer", app->grabPointer, &(app->isPointerGrabbed)); }
void grabKeyboard(AppInfo *app) { performGrab(app, GRAB_KEYBOARD, "keyboard", app->grabKeyboard, &(app->isKeyboardGrabbed)); }
KSnapshot::KSnapshot(QWidget *parent, KSnapshotObject::CaptureMode mode ) : QDialog(parent), KSnapshotObject(), modified(true), savedPosition(QPoint(-1, -1)) { // TEMPORARY Make sure "untitled" enters the string freeze for 4.6, // as explained in http://lists.kde.org/?l=kde-graphics-devel&m=128942871430175&w=2 const QString untitled = QString(tr("untitled")); setWindowTitle(""); grabber = new QWidget( 0, Qt::X11BypassWindowManagerHint ); // TODO X11 (Xinerama and Twinview, actually) and Windows use different coordinates for the two monitors case // // On Windows, there are two displays. The origin (0, 0) ('o') is the top left of display 1. If display 2 is to the left, then coordinates in display 2 are negative: // .-------. // | |o-----. // | 2 | | // | | 1 | // ._______.._____. // // On Xinerama and Twinview, there is only one display and two screens. The origin (0, 0) ('o') is the top left of the display: // o-------. // | |.-----. // | 2 | | // | | 1 | // ._______.._____. // // Instead of moving to (-10000, -10000), we should compute how many displays are and make sure we move to somewhere out of the total coordinates. // - Windows: use GetSystemMetrics ( http://msdn.microsoft.com/en-us/library/ms724385(v=vs.85).aspx ) // If moving to a negative position, we need to count the size of the dialog; moving to a positive position avoids having to compute the size of the dialog grabber->move( -10000, -10000 ); // FIXME Read above grabber->installEventFilter( this ); QVBoxLayout *vbox = new QVBoxLayout( this ); setLayout(vbox); mainWidget = new KSnapshotWidget(); vbox->addWidget(mainWidget); connect(mainWidget->ok_btn, SIGNAL(clicked()), SLOT(onOkBtnClicked())); connect(mainWidget->cancel_btn, SIGNAL(clicked()), SLOT(onCancelBtnClicked())); connect(mainWidget->save_btn, SIGNAL(clicked()), SLOT(onSaveBtnClicked())); connect(mainWidget->help_btn, SIGNAL(clicked()), SLOT(onHelpBtnClicked())); connect(mainWidget->lblImage, SIGNAL(startDrag()), SLOT(slotDragSnapshot())); connect(mainWidget->btnNew, SIGNAL(clicked()), SLOT(slotGrab())); connect(mainWidget->comboMode, SIGNAL(activated(int)), SLOT(slotModeChanged(int))); if (qApp->desktop()->numScreens() < 2) { mainWidget->comboMode->removeItem(CurrentScreen); } mainWidget->spinDelay->setSuffix(tr(" second", " seconds")); grabber->show(); grabber->grabMouse(); #ifdef HAVE_X11_EXTENSIONS_XFIXES_H { int tmp1, tmp2; //Check whether the XFixes extension is available Display *dpy = QX11Info::display(); if (!XFixesQueryExtension( dpy, &tmp1, &tmp2 )) { mainWidget->cbIncludePointer->hide(); mainWidget->lblIncludePointer->hide(); } } #elif !defined(Q_WS_WIN) mainWidget->cbIncludePointer->hide(); mainWidget->lblIncludePointer->hide(); #endif setMode(KSnapshotObject::Region); qDebug() << "Mode = " << mode; if ( mode == KSnapshotObject::FullScreen ) { snapshot = QPixmap::grabWindow( QApplication::desktop()->winId() ); #ifdef HAVE_X11_EXTENSIONS_XFIXES_H if ( haveXFixes && includePointer() ) grabPointerImage(0, 0); #endif } else if ( mode == KSnapshotObject::CurrentScreen ) { qDebug() << "Desktop Geom = " << QApplication::desktop()->geometry(); QDesktopWidget *desktop = QApplication::desktop(); int screenId = desktop->screenNumber( QCursor::pos() ); qDebug() << "Screenid = " << screenId; QRect geom = desktop->screenGeometry( screenId ); qDebug() << "Geometry = " << screenId; snapshot = QPixmap::grabWindow( desktop->winId(), geom.x(), geom.y(), geom.width(), geom.height() ); } else { setMode( mode ); switch(mode) { case KSnapshotObject::WindowUnderCursor: { setIncludeDecorations( true ); performGrab(); break; } case KSnapshotObject::ChildWindow: { slotGrab(); break; } case KSnapshotObject::Region: { grabRegion(); break; } case KSnapshotObject::FreeRegion: { grabFreeRegion(); break; } default: break; } } //When we use argument to take snapshot we mustn't hide it. if (mode != KSnapshotObject::ChildWindow) { grabber->releaseMouse(); grabber->hide(); } setDelay(0); file_path_ = QQGlobal::tempDir() + "/snapshot/snapshot.png"; connect( &grabTimer, SIGNAL(timeout()), this, SLOT(grabTimerDone()) ); connect( &updateTimer, SIGNAL(timeout()), this, SLOT(updatePreview()) ); QTimer::singleShot( 0, this, SLOT(updateCaption()) ); new QShortcut( Qt::Key_S, mainWidget->ok_btn, SLOT(animateClick())); new QShortcut( Qt::Key_N, mainWidget->btnNew, SLOT(animateClick()) ); new QShortcut( Qt::Key_Space, mainWidget->btnNew, SLOT(animateClick()) ); mainWidget->ok_btn->setFocus(); resize(QSize(400, 500)); move((QApplication::desktop()->width() - this->width()) /2, (QApplication::desktop()->height() - this->height()) /2); }
KSnapshot::KSnapshot(QWidget *parent, const char *name, bool grabCurrent) : DCOPObject("interface"), KDialogBase(parent, name, true, QString::null, Help|User1, User1, true, KStdGuiItem::quit() ) { grabber = new QWidget( 0, 0, WStyle_Customize | WX11BypassWM ); grabber->move( -1000, -1000 ); grabber->installEventFilter( this ); KStartupInfo::appStarted(); QVBox *vbox = makeVBoxMainWidget(); mainWidget = new KSnapshotWidget( vbox, "mainWidget" ); connect(mainWidget, SIGNAL(startImageDrag()), SLOT(slotDragSnapshot())); connect( mainWidget, SIGNAL( newClicked() ), SLOT( slotGrab() ) ); connect( mainWidget, SIGNAL( saveClicked() ), SLOT( slotSaveAs() ) ); connect( mainWidget, SIGNAL( printClicked() ), SLOT( slotPrint() ) ); connect( mainWidget, SIGNAL( copyClicked() ), SLOT( slotCopy() ) ); grabber->show(); grabber->grabMouse( waitCursor ); if ( !grabCurrent ) snapshot = QPixmap::grabWindow( qt_xrootwin() ); else { mainWidget->setMode( WindowUnderCursor ); mainWidget->setIncludeDecorations( true ); performGrab(); } updatePreview(); grabber->releaseMouse(); grabber->hide(); KConfig *conf=KGlobal::config(); conf->setGroup("GENERAL"); mainWidget->setDelay(conf->readNumEntry("delay",0)); mainWidget->setMode( conf->readNumEntry( "mode", 0 ) ); mainWidget->setIncludeDecorations(conf->readBoolEntry("includeDecorations",true)); filename = KURL::fromPathOrURL( conf->readPathEntry( "filename", QDir::currentDirPath()+"/"+i18n("snapshot")+"1.png" )); // Make sure the name is not already being used while(KIO::NetAccess::exists( filename, false, this )) { autoincFilename(); } connect( &grabTimer, SIGNAL( timeout() ), this, SLOT( grabTimerDone() ) ); connect( &updateTimer, SIGNAL( timeout() ), this, SLOT( updatePreview() ) ); QTimer::singleShot( 0, this, SLOT( updateCaption() ) ); KHelpMenu *helpMenu = new KHelpMenu(this, KGlobal::instance()->aboutData(), false); QPushButton *helpButton = actionButton( Help ); helpButton->setPopup(helpMenu->menu()); KAccel* accel = new KAccel(this); accel->insert(KStdAccel::Quit, kapp, SLOT(quit())); accel->insert( "QuickSave", i18n("Quick Save Snapshot &As..."), i18n("Save the snapshot to the file specified by the user without showing the file dialog."), CTRL+SHIFT+Key_S, this, SLOT(slotSave())); accel->insert(KStdAccel::Save, this, SLOT(slotSaveAs())); // accel->insert(KShortcut(CTRL+Key_A), this, SLOT(slotSaveAs())); accel->insert( "SaveAs", i18n("Save Snapshot &As..."), i18n("Save the snapshot to the file specified by the user."), CTRL+Key_A, this, SLOT(slotSaveAs())); accel->insert(KStdAccel::Print, this, SLOT(slotPrint())); accel->insert(KStdAccel::New, this, SLOT(slotGrab())); accel->insert(KStdAccel::Copy, this, SLOT(slotCopy())); accel->insert( "Quit2", Key_Q, this, SLOT(slotSave())); accel->insert( "Save2", Key_S, this, SLOT(slotSaveAs())); accel->insert( "Print2", Key_P, this, SLOT(slotPrint())); accel->insert( "New2", Key_N, this, SLOT(slotGrab())); accel->insert( "New3", Key_Space, this, SLOT(slotGrab())); setEscapeButton( User1 ); connect( this, SIGNAL( user1Clicked() ), SLOT( reject() ) ); mainWidget->btnNew->setFocus(); }