Class: Screenshot

Inherits:
Qt::Widget show all
Defined in:
ext/ruby/qtruby/examples/desktop/screenshot/screenshot.rb,
ext/ruby/qtruby/examples/widgets/screenshot/screenshot.rb

Overview

** ** Copyright © 2004-2005 Trolltech AS. All rights reserved. ** ** This file is part of the example classes of the Qt Toolkit. ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of ** this file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** www.trolltech.com/products/qt/opensource.html ** ** If you are unsure which license is appropriate for your use, please ** review the following information: ** www.trolltech.com/products/qt/licensing.html or contact the ** sales department at [email protected]. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. **

** Translated to QtRuby by Richard Dale

Instance Method Summary collapse

Methods inherited from Qt::Widget

#raise

Methods inherited from Qt::Base

#%, #&, #*, #**, #+, #-, #-@, #/, #<, #<<, #<=, #==, #>, #>=, #>>, #QCOMPARE, #QEXPECT_FAIL, #QFAIL, #QSKIP, #QTEST, #QVERIFY, #QVERIFY2, #QWARN, #^, ancestors, #is_a?, #methods, private_slots, #protected_methods, #public_methods, q_classinfo, q_signal, q_slot, signals, #singleton_methods, slots, #|, #~

Constructor Details

#initialize(parent = nil) ⇒ Screenshot

Returns a new instance of Screenshot.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'ext/ruby/qtruby/examples/desktop/screenshot/screenshot.rb', line 33

def initialize(parent = nil)
	super(parent)
    @screenshotLabel = Qt::Label.new
    @screenshotLabel.setSizePolicy(Qt::SizePolicy::Expanding,
                                   Qt::SizePolicy::Expanding)
    @screenshotLabel.alignment = Qt::AlignCenter
    @screenshotLabel.setMinimumSize(240, 160)

    createOptionsGroupBox()
    createButtonsLayout()

    self.layout = Qt::VBoxLayout.new do |m|
		m.addWidget(@screenshotLabel)
		m.addWidget(@optionsGroupBox)
		m.addLayout(@buttonsLayout)
	end

    shootScreen()
    @delaySpinBox.value = 5

    setWindowTitle(tr("Screenshot"))
    resize(300, 200)
end

Instance Method Details

#createButton(text, receiver, member) ⇒ Object



145
146
147
148
149
# File 'ext/ruby/qtruby/examples/desktop/screenshot/screenshot.rb', line 145

def createButton(text, receiver, member)
    button = Qt::PushButton.new(text)
    button.connect(button, SIGNAL(:clicked), receiver, member)
    return button
end

#createButtonsLayoutObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'ext/ruby/qtruby/examples/desktop/screenshot/screenshot.rb', line 128

def createButtonsLayout()
    @newScreenshotButton = createButton(tr("New Screenshot"),
                                       self, SLOT(:newScreenshot))

    @saveScreenshotButton = createButton(tr("Save Screenshot"),
                                        self, SLOT(:saveScreenshot))

    @quitScreenshotButton = createButton(tr("Quit"), self, SLOT(:close))

    @buttonsLayout = Qt::HBoxLayout.new do |b|
		b.addStretch()
		b.addWidget(@newScreenshotButton)
		b.addWidget(@saveScreenshotButton)
		b.addWidget(@quitScreenshotButton)
	end
end

#createOptionsGroupBoxObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'ext/ruby/qtruby/examples/desktop/screenshot/screenshot.rb', line 108

def createOptionsGroupBox()
    @optionsGroupBox = Qt::GroupBox.new(tr("Options"))

    @delaySpinBox = Qt::SpinBox.new do |s|
    	s.suffix = tr(" s")
    	s.maximum = 60
	end
    connect(@delaySpinBox, SIGNAL('valueChanged(int)'), self, SLOT(:updateCheckBox))

    @delaySpinBoxLabel = Qt::Label.new(tr("Screenshot Delay:"))

    @hideThisWindowCheckBox = Qt::CheckBox.new(tr("Hide This Window"))

    @optionsGroupBox.layout = Qt::GridLayout.new do |g|
		g.addWidget(@delaySpinBoxLabel, 0, 0)
		g.addWidget(@delaySpinBox, 0, 1)
		g.addWidget(@hideThisWindowCheckBox, 1, 0, 1, 2)
	end
end

#newScreenshotObject



66
67
68
69
70
71
72
73
# File 'ext/ruby/qtruby/examples/desktop/screenshot/screenshot.rb', line 66

def newScreenshot()
    if @hideThisWindowCheckBox.checked?
        hide()
       end
    @newScreenshotButton.disabled = true

    Qt::Timer.singleShot(@delaySpinBox.value() * 1000, self, SLOT(:shootScreen))
end

#resizeEvent(event) ⇒ Object



57
58
59
60
61
62
63
64
# File 'ext/ruby/qtruby/examples/desktop/screenshot/screenshot.rb', line 57

def resizeEvent(event)
    scaledSize = @originalPixmap.size()
    scaledSize.scale(@screenshotLabel.size(), Qt::KeepAspectRatio)
    if @screenshotLabel.pixmap.nil? ||
            scaledSize != @screenshotLabel.pixmap.size
        updateScreenshotLabel()
       end
end

#saveScreenshotObject



75
76
77
78
79
80
81
82
83
84
85
# File 'ext/ruby/qtruby/examples/desktop/screenshot/screenshot.rb', line 75

def saveScreenshot()
    format = "png"
    initialPath = Qt::Dir.currentPath() + tr("/untitled.") + format

    fileName = Qt::FileDialog.getSaveFileName(self, tr("Save As"),
                               initialPath,
                               tr("%s Files (*.%s);;All Files (*)" % [format.upcase, format]))
    if !fileName.nil?
        @originalPixmap.save(fileName, format)
       end
end

#shootScreenObject



87
88
89
90
91
92
93
94
95
96
97
98
# File 'ext/ruby/qtruby/examples/desktop/screenshot/screenshot.rb', line 87

def shootScreen()
    if @delaySpinBox.value() != 0
        $qApp.beep
       end
    @originalPixmap = Qt::Pixmap.grabWindow(Qt::Application.desktop.winId)
    updateScreenshotLabel()

    @newScreenshotButton.disabled = false
    if @hideThisWindowCheckBox.checked?
        show()
       end
end

#updateCheckBoxObject



100
101
102
103
104
105
106
# File 'ext/ruby/qtruby/examples/desktop/screenshot/screenshot.rb', line 100

def updateCheckBox()
    if @delaySpinBox.value() == 0
        @hideThisWindowCheckBox.disabled = true
    else
        @hideThisWindowCheckBox.disabled = false
       end
end

#updateScreenshotLabelObject



151
152
153
154
155
# File 'ext/ruby/qtruby/examples/desktop/screenshot/screenshot.rb', line 151

def updateScreenshotLabel()
    @screenshotLabel.pixmap = @originalPixmap.scaled(@screenshotLabel.size,
                                                     Qt::KeepAspectRatio,
                                                     Qt::SmoothTransformation)
end