Class: CharacterWidget
- Inherits:
-
Qt::Widget
show all
- Defined in:
- ext/ruby/qtruby/examples/widgets/charactermap/characterwidget.rb
Overview
** ** Copyright © 2005-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 ** self 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
Returns a new instance of CharacterWidget.
31
32
33
34
35
36
|
# File 'ext/ruby/qtruby/examples/widgets/charactermap/characterwidget.rb', line 31
def initialize(parent = nil)
super(parent)
@lastKey = -1
@displayFont = Qt::Font.new
setMouseTracking(true)
end
|
Instance Method Details
#mouseMoveEvent(event) ⇒ Object
55
56
57
58
59
|
# File 'ext/ruby/qtruby/examples/widgets/charactermap/characterwidget.rb', line 55
def mouseMoveEvent(event)
widgetPosition = mapFromGlobal(event.globalPos())
key = (widgetPosition.y()/24)*32 + widgetPosition.x()/24
Qt::ToolTip.showText(event.globalPos(), key.to_s, self)
end
|
#mousePressEvent(event) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
|
# File 'ext/ruby/qtruby/examples/widgets/charactermap/characterwidget.rb', line 61
def mousePressEvent(event)
if event.button() == Qt::LeftButton
@lastKey = (event.y()/24)*32 + event.x()/24
if Qt::Char.new(@lastKey).category() != Qt::Char::NoCategory
emit characterSelected(Qt::Char.new(@lastKey).to_s)
end
update()
else
super
end
end
|
#paintEvent(event) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'ext/ruby/qtruby/examples/widgets/charactermap/characterwidget.rb', line 73
def paintEvent(event)
painter = Qt::Painter.new(self)
painter.fillRect(event.rect(), Qt::Brush.new(Qt::white))
painter.font = @displayFont
redrawRect = event.rect()
beginRow = redrawRect.top()/24
endRow = redrawRect.bottom()/24
beginColumn = redrawRect.left()/24
endColumn = redrawRect.right()/24
painter.pen = Qt::Color.new(Qt::gray)
(beginRow..endRow).each do |row|
(beginColumn..endColumn).each do |column|
painter.drawRect(column*24, row*24, 24, 24)
end
end
fontMetrics = Qt::FontMetrics.new(@displayFont)
painter.pen = Qt::Color.new(Qt::black)
(beginRow..endRow).each do |row|
(beginColumn..endColumn).each do |column|
key = row*32 + column
painter.setClipRect(column*24, row*24, 24, 24)
if key == @lastKey
painter.fillRect(column*24, row*24, 24, 24, Qt::Brush.new(Qt::red))
end
painter.drawText( column*24 + 12 - fontMetrics.width(Qt::Char.new(key))/2,
row*24 + 4 + fontMetrics.ascent(),
Qt::Char.new(key).to_s )
end
end
painter.end
end
|
51
52
53
|
# File 'ext/ruby/qtruby/examples/widgets/charactermap/characterwidget.rb', line 51
def sizeHint()
return Qt::Size.new(32*24, (65536/32)*24)
end
|
#updateFont(fontFamily) ⇒ Object
38
39
40
41
42
|
# File 'ext/ruby/qtruby/examples/widgets/charactermap/characterwidget.rb', line 38
def updateFont(fontFamily)
@displayFont.family = fontFamily
@displayFont.pixelSize = 16
update()
end
|
#updateStyle(fontStyle) ⇒ Object
44
45
46
47
48
49
|
# File 'ext/ruby/qtruby/examples/widgets/charactermap/characterwidget.rb', line 44
def updateStyle(fontStyle)
fontDatabase = Qt::FontDatabase.new
@displayFont = fontDatabase.font(@displayFont.family(), fontStyle, 12)
@displayFont.pixelSize = 16
update()
end
|