//=========================================== // Lumina-DE source code // Copyright (c) 2014, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== #include "MainUI.h" #include "ui_MainUI.h" #include MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->setupUi(this); //load the designer file cpic = QApplication::screens().at(0)->grabWindow(QApplication::desktop()->winId()); //initial screenshot ppath = QDir::homePath(); QWidget *spacer = new QWidget(); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); ui->toolBar->insertWidget(ui->actionNew, spacer); setupIcons(); ui->spin_monitor->setMaximum(QApplication::desktop()->screenCount()); if(ui->spin_monitor->maximum()<2){ ui->spin_monitor->setEnabled(false); ui->radio_monitor->setEnabled(false); } //Setup the connections connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveScreenshot()) ); connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(closeApplication()) ); connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(startScreenshot()) ); QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QDir::homePath()+"/.lumina"); settings = new QSettings("LuminaDE", "lumina-screenshot",this); if(settings->value("screenshot-target", "window").toString() == "window") { ui->radio_window->setChecked(true); }else{ ui->radio_all->setChecked(true); } ui->spin_delay->setValue(settings->value("screenshot-delay", 0).toInt()); this->show(); ui->label_screenshot->setPixmap( cpic.scaled(ui->label_screenshot->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation) ); } MainUI::~MainUI(){} void MainUI::setupIcons(){ //Setup the icons this->setWindowIcon( LXDG::findIcon("camera-web","") ); ui->actionSave->setIcon( LXDG::findIcon("document-save","") ); ui->actionQuit->setIcon( LXDG::findIcon("application-exit","") ); ui->actionNew->setIcon( LXDG::findIcon("camera-web","") ); } //============== // PRIVATE SLOTS //============== void MainUI::saveScreenshot(){ QString filepath = QFileDialog::getSaveFileName(this, tr("Save Screenshot"), ppath, tr("PNG Files (*.png);;AllFiles (*)") ); if(filepath.isEmpty()){ return; } if(!filepath.endsWith(".png")){ filepath.append(".png"); } cpic.save(filepath, "png"); ppath = filepath; } void MainUI::startScreenshot(){ if( !getWindow() ){ return; } this->hide(); QTimer::singleShot(50+ui->spin_delay->value()*1000, this, SLOT(getPixmap())); } bool MainUI::getWindow(){ //Use this function to set cwin cwin = 0; if(ui->radio_window->isChecked()){ settings->setValue("screenshot-target", "window"); //Use xprop to get the desired window from the user QList wins = LX11::WindowList(); wins.removeAll(this->winId()); //don't show this window QStringList names; for(int i=0; iradio_monitor->isChecked()){ }else{ settings->setValue("screenshot-target", "desktop"); } settings->setValue("screenshot-delay", ui->spin_delay->value()); return true; } void MainUI::getPixmap(){ QScreen *scrn = QApplication::screens().at(0); if(cwin==0 && ui->radio_window->isChecked() ){ //Grab the whole screen cpic = scrn->grabWindow(QApplication::desktop()->winId()); }else if(cwin==0 && ui->radio_monitor->isChecked()){ QRect geom = QApplication::desktop()->screenGeometry(ui->spin_monitor->value()-1); cpic = scrn->grabWindow(QApplication::desktop()->winId(), geom.x(), geom.y(), geom.width(), geom.height() ); }else{ //Grab just the designated window cpic = scrn->grabWindow(cwin); } this->show(); //Now display the pixmap on the label as well ui->label_screenshot->setPixmap( cpic.scaled(ui->label_screenshot->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation) ); }