Screenshot Class Reference

#include <screenshot.h>

Inheritance diagram for Screenshot:

Inheritance graph
[legend]
Collaboration diagram for Screenshot:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 39 of file screenshot.h.

Public Member Functions

 Screenshot ()

Protected Member Functions

void resizeEvent (QResizeEvent *event)

Private Slots

void newScreenshot ()
void saveScreenshot ()
void shootScreen ()
void updateCheckBox ()

Private Member Functions

void createOptionsGroupBox ()
void createButtonsLayout ()
QPushButtoncreateButton (const QString &text, QWidget *receiver, const char *member)
void updateScreenshotLabel ()

Private Attributes

QPixmap originalPixmap
QLabelscreenshotLabel
QGroupBoxoptionsGroupBox
QSpinBoxdelaySpinBox
QLabeldelaySpinBoxLabel
QCheckBoxhideThisWindowCheckBox
QPushButtonnewScreenshotButton
QPushButtonsaveScreenshotButton
QPushButtonquitScreenshotButton
QVBoxLayoutmainLayout
QGridLayoutoptionsGroupBoxLayout
QHBoxLayoutbuttonsLayout


Constructor & Destructor Documentation

Screenshot::Screenshot (  ) 

Definition at line 28 of file screenshot.cpp.

References QBoxLayout::addLayout(), QBoxLayout::addWidget(), Qt::AlignCenter, buttonsLayout, createButtonsLayout(), createOptionsGroupBox(), delaySpinBox, QSizePolicy::Expanding, mainLayout, optionsGroupBox, QWidget::resize(), screenshotLabel, QLabel::setAlignment(), QWidget::setLayout(), QWidget::setMinimumSize(), QWidget::setSizePolicy(), QSpinBox::setValue(), QWidget::setWindowTitle(), and shootScreen().

Here is the call graph for this function:


Member Function Documentation

void Screenshot::resizeEvent ( QResizeEvent event  )  [protected, virtual]

This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the event parameter. When resizeEvent() is called, the widget already has its new geometry. The old size is accessible through QResizeEvent::oldSize().

The widget will be erased and receive a paint event immediately after processing the resize event. No drawing need be (or should be) done inside this handler.

See also:
moveEvent(), event(), resize(), QResizeEvent, paintEvent(), {Scribble Example}

Reimplemented from QWidget.

Definition at line 52 of file screenshot.cpp.

References Qt::KeepAspectRatio, originalPixmap, QLabel::pixmap(), QSize::scale(), screenshotLabel, QWidget::size(), QPixmap::size(), and updateScreenshotLabel().

00053 {
00054     QSize scaledSize = originalPixmap.size();
00055     scaledSize.scale(screenshotLabel->size(), Qt::KeepAspectRatio);
00056     if (!screenshotLabel->pixmap()
00057             || scaledSize != screenshotLabel->pixmap()->size())
00058         updateScreenshotLabel();
00059 }

Here is the call graph for this function:

void Screenshot::newScreenshot (  )  [private, slot]

Definition at line 61 of file screenshot.cpp.

References delaySpinBox, QWidget::hide(), hideThisWindowCheckBox, QAbstractButton::isChecked(), newScreenshotButton, QWidget::setDisabled(), shootScreen(), QTimer::singleShot(), SLOT, and QSpinBox::value().

Referenced by createButtonsLayout().

00062 {
00063     if (hideThisWindowCheckBox->isChecked())
00064         hide();
00065     newScreenshotButton->setDisabled(true);
00066 
00067     QTimer::singleShot(delaySpinBox->value() * 1000, this, SLOT(shootScreen()));
00068 }

void Screenshot::saveScreenshot (  )  [private, slot]

Definition at line 70 of file screenshot.cpp.

References QDir::currentPath(), QFileDialog::getSaveFileName(), QString::isEmpty(), originalPixmap, and QPixmap::save().

Referenced by createButtonsLayout().

00071 {
00072     QString format = "png";
00073     QString initialPath = QDir::currentPath() + tr("/untitled.") + format;
00074 
00075     QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
00076                                initialPath,
00077                                tr("%1 Files (*.%2);;All Files (*)")
00078                                .arg(format.toUpper())
00079                                .arg(format));
00080     if (!fileName.isEmpty())
00081         originalPixmap.save(fileName, format.toAscii());
00082 }

void Screenshot::shootScreen (  )  [private, slot]

Definition at line 84 of file screenshot.cpp.

References delaySpinBox, QApplication::desktop(), QPixmap::grabWindow(), hideThisWindowCheckBox, QAbstractButton::isChecked(), newScreenshotButton, originalPixmap, qApp, QWidget::setDisabled(), QWidget::show(), updateScreenshotLabel(), QSpinBox::value(), and QWidget::winId().

Referenced by newScreenshot(), and Screenshot().

00085 {
00086     if (delaySpinBox->value() != 0)
00087         qApp->beep();
00088     originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
00089     updateScreenshotLabel();
00090 
00091     newScreenshotButton->setDisabled(false);
00092     if (hideThisWindowCheckBox->isChecked())
00093         show();
00094 }

void Screenshot::updateCheckBox (  )  [private, slot]

Definition at line 96 of file screenshot.cpp.

References delaySpinBox, hideThisWindowCheckBox, QWidget::setDisabled(), and QSpinBox::value().

Referenced by createOptionsGroupBox().

00097 {
00098     if (delaySpinBox->value() == 0)
00099         hideThisWindowCheckBox->setDisabled(true);
00100     else
00101         hideThisWindowCheckBox->setDisabled(false);
00102 }

void Screenshot::createOptionsGroupBox (  )  [private]

Definition at line 104 of file screenshot.cpp.

References QGridLayout::addWidget(), QObject::connect(), delaySpinBox, delaySpinBoxLabel, hideThisWindowCheckBox, optionsGroupBox, optionsGroupBoxLayout, QWidget::setLayout(), QSpinBox::setMaximum(), QSpinBox::setSuffix(), SIGNAL, SLOT, and updateCheckBox().

Referenced by Screenshot().

00105 {
00106     optionsGroupBox = new QGroupBox(tr("Options"));
00107 
00108     delaySpinBox = new QSpinBox;
00109     delaySpinBox->setSuffix(tr(" s"));
00110     delaySpinBox->setMaximum(60);
00111     connect(delaySpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateCheckBox()));
00112 
00113     delaySpinBoxLabel = new QLabel(tr("Screenshot Delay:"));
00114 
00115     hideThisWindowCheckBox = new QCheckBox(tr("Hide This Window"));
00116 
00117     optionsGroupBoxLayout = new QGridLayout;
00118     optionsGroupBoxLayout->addWidget(delaySpinBoxLabel, 0, 0);
00119     optionsGroupBoxLayout->addWidget(delaySpinBox, 0, 1);
00120     optionsGroupBoxLayout->addWidget(hideThisWindowCheckBox, 1, 0, 1, 2);
00121     optionsGroupBox->setLayout(optionsGroupBoxLayout);
00122 }

Here is the call graph for this function:

void Screenshot::createButtonsLayout (  )  [private]

Definition at line 124 of file screenshot.cpp.

References QBoxLayout::addStretch(), QBoxLayout::addWidget(), buttonsLayout, QWidget::close(), createButton(), newScreenshot(), newScreenshotButton, quitScreenshotButton, saveScreenshot(), saveScreenshotButton, and SLOT.

Referenced by Screenshot().

00125 {
00126     newScreenshotButton = createButton(tr("New Screenshot"),
00127                                        this, SLOT(newScreenshot()));
00128 
00129     saveScreenshotButton = createButton(tr("Save Screenshot"),
00130                                         this, SLOT(saveScreenshot()));
00131 
00132     quitScreenshotButton = createButton(tr("Quit"), this, SLOT(close()));
00133 
00134     buttonsLayout = new QHBoxLayout;
00135     buttonsLayout->addStretch();
00136     buttonsLayout->addWidget(newScreenshotButton);
00137     buttonsLayout->addWidget(saveScreenshotButton);
00138     buttonsLayout->addWidget(quitScreenshotButton);
00139 }

Here is the call graph for this function:

QPushButton * Screenshot::createButton ( const QString text,
QWidget receiver,
const char *  member 
) [private]

Definition at line 141 of file screenshot.cpp.

References QObject::connect(), and SIGNAL.

Referenced by createButtonsLayout().

00143 {
00144     QPushButton *button = new QPushButton(text);
00145     button->connect(button, SIGNAL(clicked()), receiver, member);
00146     return button;
00147 }

Here is the call graph for this function:

void Screenshot::updateScreenshotLabel (  )  [private]

Definition at line 149 of file screenshot.cpp.

References Qt::KeepAspectRatio, originalPixmap, QPixmap::scaled(), screenshotLabel, QLabel::setPixmap(), QWidget::size(), and Qt::SmoothTransformation.

Referenced by resizeEvent(), and shootScreen().

Here is the call graph for this function:


Member Data Documentation

QPixmap Screenshot::originalPixmap [private]

Definition at line 62 of file screenshot.h.

Referenced by resizeEvent(), saveScreenshot(), shootScreen(), and updateScreenshotLabel().

QLabel* Screenshot::screenshotLabel [private]

Definition at line 64 of file screenshot.h.

Referenced by resizeEvent(), Screenshot(), and updateScreenshotLabel().

QGroupBox* Screenshot::optionsGroupBox [private]

Definition at line 65 of file screenshot.h.

Referenced by createOptionsGroupBox(), and Screenshot().

QSpinBox* Screenshot::delaySpinBox [private]

Definition at line 66 of file screenshot.h.

Referenced by createOptionsGroupBox(), newScreenshot(), Screenshot(), shootScreen(), and updateCheckBox().

QLabel* Screenshot::delaySpinBoxLabel [private]

Definition at line 67 of file screenshot.h.

Referenced by createOptionsGroupBox().

QCheckBox* Screenshot::hideThisWindowCheckBox [private]

Definition at line 68 of file screenshot.h.

Referenced by createOptionsGroupBox(), newScreenshot(), shootScreen(), and updateCheckBox().

QPushButton* Screenshot::newScreenshotButton [private]

Definition at line 69 of file screenshot.h.

Referenced by createButtonsLayout(), newScreenshot(), and shootScreen().

QPushButton* Screenshot::saveScreenshotButton [private]

Definition at line 70 of file screenshot.h.

Referenced by createButtonsLayout().

QPushButton* Screenshot::quitScreenshotButton [private]

Definition at line 71 of file screenshot.h.

Referenced by createButtonsLayout().

QVBoxLayout* Screenshot::mainLayout [private]

Definition at line 73 of file screenshot.h.

Referenced by Screenshot().

QGridLayout* Screenshot::optionsGroupBoxLayout [private]

Definition at line 74 of file screenshot.h.

Referenced by createOptionsGroupBox().

QHBoxLayout* Screenshot::buttonsLayout [private]

Definition at line 75 of file screenshot.h.

Referenced by createButtonsLayout(), and Screenshot().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 20:00:21 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1