qt_connect 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.LIB.txt +510 -0
- data/README.md +257 -0
- data/Rakefile +72 -0
- data/examples/classexplorer/classexplorer.rb +828 -0
- data/examples/classexplorer/menus.rb +1 -0
- data/examples/classexplorer/menus/helpmenu.rb +73 -0
- data/examples/classexplorer/packagetree.rb +91 -0
- data/examples/classexplorer/qt_extensions.rb +2 -0
- data/examples/classexplorer/qt_extensions/htmldelegate.rb +40 -0
- data/examples/classexplorer/qt_extensions/line_edit.rb +65 -0
- data/examples/deform/Deform.html +23 -0
- data/examples/deform/Thumbs.db +0 -0
- data/examples/deform/arthurframe.rb +273 -0
- data/examples/deform/deform-demo.png +0 -0
- data/examples/deform/deform.rb +502 -0
- data/examples/deform/qt-logo.png +0 -0
- data/examples/qtmapzoom/qtmapzoom.rb +340 -0
- data/java/SignalActions.java +13 -0
- data/lib/Qt.rb +10 -0
- data/lib/qt_connect.rb +12 -0
- data/lib/qt_connect/qt_compat.rb +700 -0
- data/lib/qt_connect/qt_jbindings.rb +657 -0
- data/lib/qt_connect/qt_sugar.rb +277 -0
- data/lib/qt_connect/version.rb +3 -0
- data/lib/qt_jambi.rb +8 -0
- data/lib/signalactions.jar +0 -0
- metadata +92 -0
@@ -0,0 +1 @@
|
|
1
|
+
require 'menus/helpmenu'
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Menus
|
3
|
+
class HelpMenu
|
4
|
+
|
5
|
+
def initialize(window,menubar)
|
6
|
+
@window=window
|
7
|
+
Qt::Menu.new(menubar) { |helpMenu|
|
8
|
+
menubar.addAction(helpMenu.menuAction)
|
9
|
+
helpMenu.title="Help"
|
10
|
+
# Help> Contents
|
11
|
+
Qt::Action.new(window) { |action|
|
12
|
+
action.text="Contents"
|
13
|
+
action.icon=window.style.standardIcon(Qt::Style::SP_DesktopIcon)
|
14
|
+
|
15
|
+
action.triggered.connect { Qt::MessageBox.about(window,'Qt_connect',contents)}
|
16
|
+
helpMenu.addAction(action)
|
17
|
+
}
|
18
|
+
helpMenu.addSeparator
|
19
|
+
#Help> About Qt
|
20
|
+
Qt::Action.new(window) { |action|
|
21
|
+
action.text="About Qt"
|
22
|
+
action.triggered.connect { Qt::MessageBox.aboutQt(window) } #$qApp.aboutQt}
|
23
|
+
helpMenu.addAction(action)
|
24
|
+
}
|
25
|
+
helpMenu.addSeparator
|
26
|
+
#Help> About Qt Jambi
|
27
|
+
Qt::Action.new(window) { |action|
|
28
|
+
action.text="About Qt Jambi"
|
29
|
+
action.triggered.connect { $qApp.aboutQtJambi } #$qApp.aboutQt}
|
30
|
+
helpMenu.addAction(action)
|
31
|
+
}
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def contents
|
36
|
+
%Q[
|
37
|
+
<html><h1>Qt_Connect Class Explorer</h1>
|
38
|
+
<font size="+1">
|
39
|
+
<p>This browser extends the Javadoc documentation for the <b>com.trolltech.qt</b> Java packages that form
|
40
|
+
the basis for the JRuby Qt Jambi API.</p>
|
41
|
+
<p>The left hand top frame displays all packages found on the Java CLASSPATH which implement the Qt framework.
|
42
|
+
You can select one or more of these packages for inspection. By default all packages are selected.<br/>
|
43
|
+
The lower panel displays all Classes and Interfaces which belong to the selected packages mapped to
|
44
|
+
the same Ruby <b>Qt</b> namespace.</p>
|
45
|
+
<p>The mapping rules from full-package name for each class in Java to Ruby namespace
|
46
|
+
are simple: when a class name starts with either 'Qt' or 'Q' that part of the name is dropped, otherwise it is unchanged.</p>
|
47
|
+
Examples:</p>
|
48
|
+
<table cellpadding="3" cellspacing="0">
|
49
|
+
<tr><td>com.trolltech.qt.QSysInfo</td><td>Qt::SysInfo</td></tr>
|
50
|
+
<tr><td>com.trolltech.qt.Utilities</td><td>Qt::Utilities</td></tr>
|
51
|
+
<tr><td>com.trolltech.qt.gui.QToolButton</td><td>Qt::ToolButton</td></tr>
|
52
|
+
<tr><td>com.trolltech.qt.svg.QSvgWidget</td><td>Qt::SvgWidget</td></tr>
|
53
|
+
<tr><td>com.trolltech.qt.QtEnumerator</td><td>Qt::Enumerator</td></tr>
|
54
|
+
</table>
|
55
|
+
<p>The number of classes displayed can be narrowed down by entering a filter value in the bottom field</p>
|
56
|
+
<p>The next panel displays a summary for the selected Class or Interface from the JRuby perspective: Java fields and methods
|
57
|
+
are mapped to Ruby Constants, Class Methods and Instance Methods. Fields inheriting the SignalEmitter class are
|
58
|
+
separately listed as <b>Signals</b> with prototypes of the methods or blocks they can connect to.</p>
|
59
|
+
<p>Constants which inherit the Qt::Enumerator module are separately listed as <b>Enums</b> with their enumerated values and shorthand
|
60
|
+
notations.</p>
|
61
|
+
<p>In the right-hand top of the panel a box can be ticked to include or exclude members of inherited Qt classes. If you tick the
|
62
|
+
<em>'link to Qt Jambi Reference Documentation'</em> box, a separate (dockable) window opens displaying the matching Javadoc documentation.
|
63
|
+
If you use this feature, make sure the Javadoc root url matches the version of Qt Jambi you have installed.</p>
|
64
|
+
<p>
|
65
|
+
|
66
|
+
|
67
|
+
</p></font></html>
|
68
|
+
]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'qt_connect'
|
3
|
+
|
4
|
+
#Scans all classes accessible from JRuby runtime classloader
|
5
|
+
#Cees Zeelenberg (c.zeelenberg@computer.org)
|
6
|
+
#partially adapted from: snippets.dzone.com/posts/show/4831 (Java)
|
7
|
+
#N.B. filters out selected classes specific to QtJambi !!!
|
8
|
+
|
9
|
+
#PackageTree#keys => [packagename + subpackage names]
|
10
|
+
#PackageTree#values => [all packages in tree]
|
11
|
+
#PackageTree['packagename'] => package
|
12
|
+
#Package#classes => [classnames in package]
|
13
|
+
#Cees Zeelenberg
|
14
|
+
|
15
|
+
#Get all classes within a package
|
16
|
+
class PackageTree < Hash
|
17
|
+
|
18
|
+
class Package
|
19
|
+
attr_accessor :classes,:innerclasses,:path,:parent,:children
|
20
|
+
def initialize(packagetree,package_name)
|
21
|
+
@package_name=package_name
|
22
|
+
@packagetree=packagetree
|
23
|
+
@classes=[]
|
24
|
+
@children=[]
|
25
|
+
pp=package_name.split('.').slice(0...-1).join('.')
|
26
|
+
@parent=(pp.size>0) ? (packagetree[pp] || Package.new(packagetree,pp)) : nil
|
27
|
+
@parent.children << self if @parent
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(root_package_name)
|
32
|
+
@root_package_name=root_package_name
|
33
|
+
@packages=super()
|
34
|
+
@packages[root_package_name]= Package.new(self,root_package_name)
|
35
|
+
@jars={}
|
36
|
+
path=@root_package_name.gsub('.','/')
|
37
|
+
class_loader=JRuby.runtime.jruby_class_loader
|
38
|
+
resources=class_loader.getResources(path)
|
39
|
+
dirs=[]
|
40
|
+
while resources.hasMoreElements
|
41
|
+
resource=resources.nextElement
|
42
|
+
dirs << resource.getFile
|
43
|
+
end
|
44
|
+
classpaths=[]
|
45
|
+
dirs.each{ |dir| classpaths += findClasses(dir,@root_package_name)}
|
46
|
+
classpaths.uniq.each{ |klasspath|
|
47
|
+
next if klasspath.end_with?('$ConcreteWrapper')
|
48
|
+
next if klasspath.end_with?('$QtJambi_LibrariInitializer')
|
49
|
+
next if klasspath.end_with?('$1') #anonymous inner class?
|
50
|
+
elems=klasspath.split('.')
|
51
|
+
klass=elems.pop
|
52
|
+
package_name=elems.join('.')
|
53
|
+
@packages[package_name]=package=@packages[package_name] || Package.new(self,package_name)
|
54
|
+
package.classes << klass
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def jars
|
59
|
+
return @jars.keys.join(',')
|
60
|
+
end
|
61
|
+
|
62
|
+
def findClasses(path,package_name)
|
63
|
+
classes=[]
|
64
|
+
if path.start_with?("file:") && path.include?("!")
|
65
|
+
split=path.split("!")
|
66
|
+
jar=java.net.URL.new(split[0])
|
67
|
+
@jars[split[0][6..-1]]=true
|
68
|
+
zip=java.util.zip.ZipInputStream.new(jar.openStream)
|
69
|
+
while entry=zip.getNextEntry
|
70
|
+
if entry.getName.end_with?(".class")
|
71
|
+
class_name=entry.getName.gsub(/[.]class/,'').gsub('/','.')
|
72
|
+
classes << class_name if class_name.start_with?(package_name)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
dir=java.io.File.new(path)
|
77
|
+
return classes if !dir.exists
|
78
|
+
dir.listFiles.each{ |file|
|
79
|
+
|
80
|
+
if file.isDirectory
|
81
|
+
raise 'hell' if file.include?('.')
|
82
|
+
classes += findClasses(file.getAbsolutePath, package_name + '.' + file.getName)
|
83
|
+
elsif file.getName.end_with?(".class")
|
84
|
+
classes += Java::Class.forName(package_name + '.' + file.getName[0..-7])
|
85
|
+
end
|
86
|
+
}
|
87
|
+
return classes
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#
|
2
|
+
#Itemdelegate allowing the use of html-formatted items
|
3
|
+
#use stylesheets for special formatting of tagged text (see defaultdoc)
|
4
|
+
#provide external Qt::TextDocument (HtmlDelegat#doc=) for more flexibility
|
5
|
+
|
6
|
+
module QtExtensions
|
7
|
+
class HtmlDelegate < Qt::ItemDelegate
|
8
|
+
attr_accessor :doc
|
9
|
+
|
10
|
+
def paint(painter, option, index)
|
11
|
+
drawBackground(painter,option,index)
|
12
|
+
@doc||= defaultdoc
|
13
|
+
item=index.model.data(index).toString
|
14
|
+
if (option.state.value & Qt::Style::State_Selected.value) !=0
|
15
|
+
item=%Q[<span class="selected">#{item}</span>]
|
16
|
+
end
|
17
|
+
|
18
|
+
@doc.setHtml(item)
|
19
|
+
painter.save
|
20
|
+
painter.translate(option.rect.topLeft)
|
21
|
+
r=Qt::RectF.new(0,0,option.rect.width,option.rect.height)
|
22
|
+
@doc.drawContents(painter,r)
|
23
|
+
painter.restore
|
24
|
+
end
|
25
|
+
|
26
|
+
def defaultdoc
|
27
|
+
return Qt::TextDocument.new { |d|
|
28
|
+
d.defaultStyleSheet=%Q[.hilite {background-color: yellow;color:black; }
|
29
|
+
.selected {color: white}
|
30
|
+
.special {color: goldenrod}
|
31
|
+
]}
|
32
|
+
end
|
33
|
+
|
34
|
+
def sizeHint(option,index)
|
35
|
+
@doc||=defaultdoc
|
36
|
+
@doc.setHtml(index.model.data(index).toString)
|
37
|
+
return @doc.size.toSize
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#
|
2
|
+
#Qt::LineEdit
|
3
|
+
#extended with Clearbutton Icon in right handcorner (SP_BrowserStop)
|
4
|
+
#extended with Placeholdertext in Grey when empty and not in focus
|
5
|
+
#functionality (partially?) added for Qt 4.7
|
6
|
+
|
7
|
+
module QtExtensions
|
8
|
+
class LineEdit < Qt::LineEdit
|
9
|
+
def setClearButton
|
10
|
+
@clearButton=Qt::ToolButton.new(self){ |b|
|
11
|
+
b.icon=style.standardIcon(Qt::Style::SP_BrowserStop)
|
12
|
+
b.iconSize=Qt::Size.new(16,16)
|
13
|
+
b.cursor=Qt::Cursor.new(Qt::ArrowCursor)
|
14
|
+
b.styleSheet="border:none; padding: 0px;"
|
15
|
+
b.hide
|
16
|
+
b.clicked.connect{self.clear}
|
17
|
+
}
|
18
|
+
self.textChanged.connect{ |s| @clearButton.visible=(s.size>0)}
|
19
|
+
frameWidth=self.style.pixelMetric(Qt::Style::PM_DefaultFrameWidth)
|
20
|
+
padding=@clearButton.sizeHint.width+frameWidth+1
|
21
|
+
self.styleSheet="padding-right: #{padding}px;"
|
22
|
+
msz=self.minimumSizeHint
|
23
|
+
self.minimumSize=Qt::Size.new(
|
24
|
+
[msz.width,@clearButton.sizeHint.height+frameWidth*2+2].max,
|
25
|
+
[msz.height,@clearButton.sizeHint.height+frameWidth*2+2].max)
|
26
|
+
end
|
27
|
+
|
28
|
+
def resizeEvent(event)
|
29
|
+
super(event)
|
30
|
+
if @clearButton
|
31
|
+
sz=@clearButton.sizeHint
|
32
|
+
frameWidth=self.style.pixelMetric(Qt::Style::PM_DefaultFrameWidth)
|
33
|
+
@clearButton.move(rect.right-frameWidth-sz.width,
|
34
|
+
(rect.bottom+1-sz.height)/2)
|
35
|
+
end
|
36
|
+
if @placeholder
|
37
|
+
sz=@placeholder.sizeHint
|
38
|
+
@placeholder.move(2,2)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def placeholderText=(s)
|
43
|
+
@placeholder.text='' if @placeholder
|
44
|
+
@placeholder=Qt::Label.new(self) { |p|
|
45
|
+
p.styleSheet="color:grey;font:italic;"
|
46
|
+
p.move(2,2)
|
47
|
+
p.minimumWidth=self.width-4
|
48
|
+
p.text=s
|
49
|
+
p.visible=true
|
50
|
+
}
|
51
|
+
end
|
52
|
+
def focusInEvent(e)
|
53
|
+
@placeholder.visible=false if @placeholder
|
54
|
+
super(e)
|
55
|
+
end
|
56
|
+
def focusOutEvent(e)
|
57
|
+
@placeholder.visible=(text.size==0) if @placeholder
|
58
|
+
super(e)
|
59
|
+
end
|
60
|
+
def text=(x)
|
61
|
+
@placeholder.visible=((x.size==0) && !hasFocus) if @placeholder
|
62
|
+
super(x)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<!-- ../src/demos/deform.qdoc -->
|
6
|
+
<head>
|
7
|
+
<title>Vector Deformation</title>
|
8
|
+
<style type="text/css">h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
|
9
|
+
a:link { color: #004faf; text-decoration: none }
|
10
|
+
a:visited { color: #672967; text-decoration: none }
|
11
|
+
td.postheader { font-family: sans-serif }
|
12
|
+
tr.address { font-family: sans-serif }
|
13
|
+
body { color: black; }</style>
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
<h1 class="title">Vector Deformation<br /><span class="subtitle"></span>
|
17
|
+
</h1>
|
18
|
+
<p>This demo shows how to use advanced vector techniques to draw text using a <tt>QPainterPath</tt>.</p>
|
19
|
+
<p align="center"><img src="deform-demo.png" /></p><p>We define a vector deformation field in the shape of a lens and apply this to all points in a path. This means that what is rendered on screen is not pixel manipulation, but modified vector representations of the glyphs themselves. This is visible from the high quality of the antialiased edges for the deformed glyphs.</p>
|
20
|
+
<p>To get a fairly complex path we allow the user to type in text and convert the text to paths. This is done using the QPainterPath::addText() method.</p>
|
21
|
+
<p>The lens is drawn using a single call to QPainter::drawEllipse(), using a QRadialGradient to fill it with a specialized color table, giving the effect of the sun's reflection and a drop shadow. The lens is cached as a pixmap for better performance.</p>
|
22
|
+
</body>
|
23
|
+
</html>
|
Binary file
|
@@ -0,0 +1,273 @@
|
|
1
|
+
=begin
|
2
|
+
**
|
3
|
+
** Copyright (C) 1992-2009 Nokia. All rights reserved.
|
4
|
+
**
|
5
|
+
** This file is part of Qt Jambi.
|
6
|
+
**
|
7
|
+
** ** $BEGIN_LICENSE$
|
8
|
+
** Commercial Usage
|
9
|
+
** Licensees holding valid Qt Commercial licenses may use this file in
|
10
|
+
** accordance with the Qt Commercial License Agreement provided with the
|
11
|
+
** Software or, alternatively, in accordance with the terms contained in
|
12
|
+
** a written agreement between you and Nokia.
|
13
|
+
**
|
14
|
+
** GNU Lesser General Public License Usage
|
15
|
+
** Alternatively, this file may be used under the terms of the GNU Lesser
|
16
|
+
** General Public License version 2.1 as published by the Free Software
|
17
|
+
** Foundation and appearing in the file LICENSE.LGPL included in the
|
18
|
+
** packaging of this file. Please review the following information to
|
19
|
+
** ensure the GNU Lesser General Public License version 2.1 requirements
|
20
|
+
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
21
|
+
**
|
22
|
+
** In addition, as a special exception, Nokia gives you certain
|
23
|
+
** additional rights. These rights are described in the Nokia Qt LGPL
|
24
|
+
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
25
|
+
** package.
|
26
|
+
**
|
27
|
+
** GNU General Public License Usage
|
28
|
+
** Alternatively, this file may be used under the terms of the GNU
|
29
|
+
** General Public License version 3.0 as published by the Free Software
|
30
|
+
** Foundation and appearing in the file LICENSE.GPL included in the
|
31
|
+
** packaging of this file. Please review the following information to
|
32
|
+
** ensure the GNU General Public License version 3.0 requirements will be
|
33
|
+
** met: http://www.gnu.org/copyleft/gpl.html.
|
34
|
+
**
|
35
|
+
** If you are unsure which license is appropriate for your use, please
|
36
|
+
** contact the sales department at qt-sales@nokia.com.
|
37
|
+
** $END_LICENSE$
|
38
|
+
|
39
|
+
**
|
40
|
+
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
41
|
+
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
42
|
+
**
|
43
|
+
** Ruby implementation by by Cees Zeelenberg
|
44
|
+
=end
|
45
|
+
|
46
|
+
|
47
|
+
class ArthurFrame < Qt::Widget
|
48
|
+
|
49
|
+
attr_accessor :descriptionEnabledChanged
|
50
|
+
|
51
|
+
def initialize(parent)
|
52
|
+
@prefer_image = true
|
53
|
+
@show_doc = false
|
54
|
+
@document = nil
|
55
|
+
@sourceFilename = ""
|
56
|
+
|
57
|
+
@static_image = nil
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
super(parent)
|
62
|
+
@descriptionEnabledChanged = Qt::Signal.new
|
63
|
+
@tile = Qt::Pixmap.new(100, 100)
|
64
|
+
@tile.fill(Qt::Color.white)
|
65
|
+
color = Qt::Color.new(240, 240, 240)
|
66
|
+
pt = Qt::Painter.new
|
67
|
+
pt.begin(@tile)
|
68
|
+
pt.fillRect(0, 0, 50, 50, Qt::Brush.new(color))
|
69
|
+
pt.fillRect(50, 50, 50, 50, Qt::Brush.new(color))
|
70
|
+
pt.end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def paint(painter)
|
75
|
+
super(painter)
|
76
|
+
end
|
77
|
+
|
78
|
+
def loadDescription(filename)
|
79
|
+
textFile = Qt::File.new(filename)
|
80
|
+
if !textFile.open(Qt::File::ReadOnly)
|
81
|
+
text = "Unable to load resource file: " + filename
|
82
|
+
else
|
83
|
+
ba = textFile.readAll
|
84
|
+
codec = Qt::TextCodec.codecForHtml(ba)
|
85
|
+
text = codec.toUnicode(ba)
|
86
|
+
end
|
87
|
+
setDescription(text)
|
88
|
+
end
|
89
|
+
|
90
|
+
def setDescription(description)
|
91
|
+
@document = Qt::TextDocument.new(self)
|
92
|
+
@document.setHtml(description)
|
93
|
+
end
|
94
|
+
|
95
|
+
def paintDescription(painter)
|
96
|
+
return unless @document
|
97
|
+
|
98
|
+
pageWidth = [width - 100, 100].max
|
99
|
+
pageHeight = [height - 100, 100].max
|
100
|
+
|
101
|
+
@document.setPageSize(Qt::SizeF.new(pageWidth, pageHeight)) if pageWidth != @document.pageSize.width
|
102
|
+
|
103
|
+
textRect = Qt::Rect.new(width / 2 - pageWidth / 2,
|
104
|
+
height / 2 - pageHeight / 2,
|
105
|
+
pageWidth, pageHeight)
|
106
|
+
pad = 10
|
107
|
+
clearRect = textRect.adjusted(-pad, -pad, pad, pad)
|
108
|
+
painter.setPen(Qt::NoPen)
|
109
|
+
painter.setBrush(Qt::Brush.new(Qt::Color.new(0, 0, 0, 63)))
|
110
|
+
shade = 10
|
111
|
+
|
112
|
+
painter.drawRect(clearRect.x + clearRect.width + 1,
|
113
|
+
clearRect.y + shade,
|
114
|
+
shade, clearRect.height + 1)
|
115
|
+
painter.drawRect(clearRect.x + shade, clearRect.y + clearRect.height + 1,
|
116
|
+
clearRect.width - shade + 1, shade)
|
117
|
+
painter.setRenderHint(Qt::Painter::Antialiasing, false)
|
118
|
+
painter.setBrush(Qt::Brush.new(Qt::Color.new(255, 255, 255, 220)))
|
119
|
+
painter.setPen(Qt::Color.black)
|
120
|
+
painter.drawRect(clearRect)
|
121
|
+
|
122
|
+
painter.setClipRegion(Qt::Region.new(textRect), Qt::IntersectClip)
|
123
|
+
painter.translate(textRect.topLeft)
|
124
|
+
|
125
|
+
ctx =Qt::AbstractTextDocumentLayout::PaintContext.new
|
126
|
+
g = Qt::LinearGradient.new(0, 0, 0, textRect.height) {
|
127
|
+
setColorAt(0, Qt::Color.black)
|
128
|
+
setColorAt(0.9, Qt::Color.black)
|
129
|
+
setColorAt(1, Qt::Color.transparent)
|
130
|
+
}
|
131
|
+
pal = Qt::Palette.new
|
132
|
+
pal.setBrush(Qt::Palette::Text, Qt::Brush.new(g))
|
133
|
+
ctx.setPalette(pal)
|
134
|
+
ctx.setClip(Qt::RectF.new(0, 0, textRect.width, textRect.height))
|
135
|
+
@document.documentLayout.draw(painter, ctx)
|
136
|
+
end
|
137
|
+
|
138
|
+
def loadSourceFile(sourceFile)
|
139
|
+
@sourceFilename = sourceFile
|
140
|
+
end
|
141
|
+
|
142
|
+
def showSource(tf)
|
143
|
+
f = Qt::File.new(@sourceFilename)
|
144
|
+
if !f.open(Qt::File::ReadOnly)
|
145
|
+
contents = "Could not open file: " + @sourceFilename
|
146
|
+
else
|
147
|
+
ba = f.readAll
|
148
|
+
codec = Qt::TextCodec.codecForLocale
|
149
|
+
contents = codec.toUnicode(ba)
|
150
|
+
end
|
151
|
+
f.close
|
152
|
+
contents = contents.gsub("&", "&")
|
153
|
+
contents = contents.gsub("<", "<")
|
154
|
+
contents = contents.gsub(">", ">")
|
155
|
+
|
156
|
+
keywords=%w(for if switch int const void case double static new this package true false public protected
|
157
|
+
private final native import extends implements else class super for)
|
158
|
+
|
159
|
+
keywords.each{| keyword|
|
160
|
+
contents = contents.gsub(keyword){ |m| "<font color=olive>" + keyword + "</font>"}
|
161
|
+
}
|
162
|
+
contents = contents.gsub("(int ", "(<font color=olive><b>int </b></font>")
|
163
|
+
contents = contents.gsub("(\\d\\d?)", "<font color=navy>$1</font>")
|
164
|
+
|
165
|
+
commentRe = "(//.+)\\n"
|
166
|
+
# commentRe.setMinimal(true)
|
167
|
+
contents = contents.gsub(commentRe, "<font color=red>$1</font>\n")
|
168
|
+
|
169
|
+
stringLiteralRe = "(\".+\")"
|
170
|
+
# stringLiteralRe.setMinimal(true)
|
171
|
+
contents = contents.gsub(stringLiteralRe, "<font color=green>$1</font>")
|
172
|
+
|
173
|
+
html = contents
|
174
|
+
@html = "<html><pre>" + html + "</pre></html>"
|
175
|
+
|
176
|
+
@sourceViewer = Qt::TextBrowser.new { |v|
|
177
|
+
v.setWindowTitle("Source: + #{@sourceFilename}")
|
178
|
+
v.setAttribute(Qt::WA_DeleteOnClose)
|
179
|
+
v.setHtml(@html)
|
180
|
+
v.resize(600, 600)
|
181
|
+
v.show
|
182
|
+
}
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
def preferImage
|
187
|
+
return @prefer_image
|
188
|
+
end
|
189
|
+
|
190
|
+
def setPreferImage(pi)
|
191
|
+
@prefer_image = pi
|
192
|
+
end
|
193
|
+
|
194
|
+
def setDescriptionEnabled(enabled)
|
195
|
+
if (@show_doc != enabled)
|
196
|
+
@show_doc = enabled
|
197
|
+
@descriptionEnabledChanged.emit(@show_doc)
|
198
|
+
update
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
#@Override
|
203
|
+
def paintEvent(e)
|
204
|
+
painter = Qt::Painter.new
|
205
|
+
if (preferImage)
|
206
|
+
if @static_image.nil?
|
207
|
+
@static_image = Qt::Image.new(size, Qt::Image::Format_RGB32)
|
208
|
+
elsif @static_image.size.width != size.width || @static_image.size.height != size.height
|
209
|
+
@static_image = Qt::Image.new(size, Qt::Image::Format_RGB32)
|
210
|
+
end
|
211
|
+
|
212
|
+
painter.begin(@static_image)
|
213
|
+
o = 10
|
214
|
+
|
215
|
+
bg = palette.brush(Qt::Palette::Window)
|
216
|
+
painter.fillRect(0, 0, o, o, bg)
|
217
|
+
painter.fillRect(width - o, 0, o, o, bg)
|
218
|
+
painter.fillRect(0, height - o, o, o, bg)
|
219
|
+
painter.fillRect(width - o, height - o, o, o, bg)
|
220
|
+
else
|
221
|
+
painter.begin(self)
|
222
|
+
end
|
223
|
+
|
224
|
+
painter.setClipRect(e.rect)
|
225
|
+
painter.setRenderHint(Qt::Painter::Antialiasing)
|
226
|
+
|
227
|
+
r = rect
|
228
|
+
left = r.x + 1
|
229
|
+
top = r.y + 1
|
230
|
+
right = r.right
|
231
|
+
bottom = r.bottom
|
232
|
+
radius2 = 8 * 2
|
233
|
+
|
234
|
+
clipPath = Qt::PainterPath.new{
|
235
|
+
moveTo(right - radius2, top)
|
236
|
+
arcTo(right - radius2, top, radius2, radius2, 90, -90)
|
237
|
+
arcTo(right - radius2, bottom - radius2, radius2, radius2, 0, -90)
|
238
|
+
arcTo(left, bottom - radius2, radius2, radius2, 270, -90)
|
239
|
+
arcTo(left, top, radius2, radius2, 180, -90)
|
240
|
+
closeSubpath
|
241
|
+
}
|
242
|
+
|
243
|
+
painter.save
|
244
|
+
painter.setClipPath(clipPath, Qt::IntersectClip)
|
245
|
+
painter.drawTiledPixmap(rect, @tile)
|
246
|
+
|
247
|
+
paint(painter)
|
248
|
+
|
249
|
+
painter.restore
|
250
|
+
|
251
|
+
painter.save
|
252
|
+
|
253
|
+
paintDescription(painter) if (@show_doc)
|
254
|
+
painter.restore
|
255
|
+
|
256
|
+
level = 180
|
257
|
+
painter.setPen(Qt::Pen.new(Qt::Brush.new(Qt::Color.new(level, level, level)), 2))
|
258
|
+
painter.setBrush(Qt::NoBrush)
|
259
|
+
painter.drawPath(clipPath)
|
260
|
+
|
261
|
+
if (preferImage)
|
262
|
+
painter.end
|
263
|
+
painter.begin(self)
|
264
|
+
painter.drawImage(e.rect, @static_image, e.rect)
|
265
|
+
end
|
266
|
+
|
267
|
+
painter.end
|
268
|
+
end
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
end
|