~kubuntu-members/korundum/4.11

« back to all changes in this revision

Viewing changes to plasma/tools/plasmoidviewer/fullview.rb

  • Committer: Ian Monroe
  • Date: 2010-11-21 15:55:01 UTC
  • Revision ID: git-v1:c37670e4e3c59f5eb2ba112f5341a5e706217f6f
Split up Smoke into Qt and KDE directories. 
Move libsmoke stuff into the generator directory
Split up Ruby into qtruby and korundum directories

svn path=/trunk/KDE/kdebindings/ruby/; revision=1199320

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
=begin
2
 
/*
3
 
 * Copyright 2007 Frerich Raabe <raabe@kde.org>
4
 
 * Copyright 2007 Aaron Seigo <aseigo@kde.org
5
 
 *
6
 
 * Translated to Ruby by Richard Dale
7
 
 *
8
 
 * Redistribution and use in source and binary forms, with or without
9
 
 * modification, are permitted provided that the following conditions
10
 
 * are met:
11
 
 *
12
 
 * 1. Redistributions of source code must retain the above copyright
13
 
 *    notice, this list of conditions and the following disclaimer.
14
 
 * 2. Redistributions in binary form must reproduce the above copyright
15
 
 *    notice, this list of conditions and the following disclaimer in the
16
 
 *    documentation and/or other materials provided with the distribution.
17
 
 *
18
 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 
 */
29
 
 
30
 
=end
31
 
 
32
 
require 'plasma_applet'
33
 
 
34
 
class FullView < Qt::GraphicsView
35
 
  slots 'sceneRectChanged(QRectF)',
36
 
        'resizeEvent(QResizeEvent)'
37
 
 
38
 
  def initialize(ff = "planar", loc = "floating", parent = nil)
39
 
    super()
40
 
    @formfactor = Plasma::Planar
41
 
    @location = Plasma::Floating
42
 
    @containment = nil
43
 
    @applet = nil
44
 
    @corona = Plasma::Corona.new
45
 
 
46
 
    setFrameStyle(Qt::Frame::NoFrame)
47
 
    formfactor = ff.downcase
48
 
    if formfactor.empty? || formfactor == "planar"
49
 
        @formfactor = Plasma::Planar
50
 
    elsif formfactor == "vertical"
51
 
        @formfactor = Plasma::Vertical
52
 
    elsif formfactor == "horizontal"
53
 
        @formfactor = Plasma::Horizontal
54
 
    elsif formfactor == "mediacenter"
55
 
        @formfactor = Plasma::MediaCenter
56
 
    end
57
 
 
58
 
    location = loc.downcase
59
 
    if loc.empty? || loc == "floating"
60
 
        @location = Plasma::Floating
61
 
    elsif loc == "desktop"
62
 
        @location = Plasma::Desktop
63
 
    elsif loc == "fullscreen"
64
 
        @location = Plasma::FullScreen
65
 
    elsif loc == "top"
66
 
        @location = Plasma::TopEdge
67
 
    elsif loc == "bottom"
68
 
        @location = Plasma::BottomEdge
69
 
    elsif loc == "right"
70
 
        @location = Plasma::RightEdge
71
 
    elsif loc == "left"
72
 
        @location = Plasma::LeftEdge
73
 
    end
74
 
 
75
 
    setScene(@corona)
76
 
    connect(@corona, SIGNAL('sceneRectChanged(QRectF)'),
77
 
            self, SLOT('sceneRectChanged(QRectF)'))
78
 
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff)
79
 
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff)
80
 
    setAlignment(Qt::AlignLeft | Qt::AlignTop)
81
 
  end
82
 
 
83
 
  def addApplet(a, args)
84
 
    @containment = @corona.addContainment("null")
85
 
    @containment.formFactor = @formfactor
86
 
    @containment.location = @location
87
 
    @applet = @containment.addApplet(a, args, Qt::RectF.new(0, 0, -1, -1))
88
 
    @applet.setFlag(Qt::GraphicsItem::ItemIsMovable, false)
89
 
 
90
 
    setSceneRect(@applet.geometry)
91
 
    setWindowTitle(@applet.name)
92
 
    setWindowIcon(Qt::Icon.new(KDE::SmallIcon(@applet.icon)))
93
 
  end
94
 
 
95
 
  def resizeEvent(event)
96
 
    if @applet.nil?
97
 
        puts "no applet"
98
 
        return
99
 
    end
100
 
 
101
 
    # The applet always keeps its aspect ratio, so let's respect it.
102
 
    newWidth = 0
103
 
    newHeight = 0
104
 
 
105
 
    if @applet.aspectRatioMode == Qt::KeepAspectRatio
106
 
      ratio = event.oldSize.width / event.oldSize.height
107
 
      newPossibleWidth = size.height * ratio
108
 
      if newPossibleWidth > size.width
109
 
        newHeight = size.width / ratio
110
 
        newWidth = newHeight * ratio
111
 
      else
112
 
        newWidth = newPossibleWidth
113
 
        newHeight = newWidth / ratio
114
 
      end
115
 
    else
116
 
      newWidth = size.width
117
 
      newHeight = size.height
118
 
    end
119
 
 
120
 
    @containment.resize(Qt::SizeF.new(size()))
121
 
    @applet.resize(Qt::SizeF.new(newWidth, newHeight))
122
 
  end
123
 
 
124
 
  def sceneRectChanged(rect)
125
 
    if @applet
126
 
      setSceneRect(@applet.geometry)
127
 
    end
128
 
  end
129
 
end
130
 
 
131
 
description = I18N_NOOP( "Run Plasma applets in their own window" )
132
 
version = "1.0"
133
 
aboutData = KDE::AboutData.new( "plasmoidviewer", nil, KDE::ki18n( "Plasma Applet Viewer" ),
134
 
                                version, KDE::ki18n( description ), KDE::AboutData::License_BSD,
135
 
                                KDE::ki18n( "(C) 2007, The KDE Team" ) )
136
 
aboutData.addAuthor( KDE::ki18n( "Frerich Raabe" ),
137
 
                     KDE::ki18n( "Original author" ),
138
 
                     "raabe@kde.org" )
139
 
 
140
 
KDE::CmdLineArgs.init( ARGV, aboutData )
141
 
 
142
 
options = KDE::CmdLineOptions.new
143
 
options.add( "f" )
144
 
options.add( "formfactor <name>", KDE::ki18n( "The formfactor to use (horizontal, vertical, mediacenter or planar)" ), "planar")
145
 
options.add( "l" )
146
 
options.add( "location <name>", KDE::ki18n( "The location constraint to start the Containment with (floating, desktop, fullscreen, top, bottom, left, right)" ), "floating")
147
 
options.add( "p" )
148
 
options.add( "pixmapcache <size>", KDE::ki18n("The size in KB to set the pixmap cache to"))
149
 
options.add( "!+applet", KDE::ki18n( "Name of applet to add (required)" ) )
150
 
options.add( "+[args]", KDE::ki18n( "Optional arguments of the applet to add" ) )
151
 
KDE::CmdLineArgs.addCmdLineOptions( options )
152
 
 
153
 
app = KDE::Application.new
154
 
 
155
 
args = KDE::CmdLineArgs.parsedArgs
156
 
 
157
 
if args.count == 0
158
 
  KDE::CmdLineArgs.usageError(KDE::i18n("No applet name specified"))
159
 
end
160
 
 
161
 
formfactor = "planar"
162
 
if args.isSet("formfactor")
163
 
  puts "setting FormFactor to #{args.getOption("formfactor")}"
164
 
  formfactor = args.getOption("formfactor")
165
 
end
166
 
 
167
 
location = "floating"
168
 
if args.isSet("location")
169
 
  puts "setting Location to #{args.getOption("location")}"
170
 
  location = args.getOption("location")
171
 
end
172
 
 
173
 
appletArgs = []
174
 
for i in 1...args.count do
175
 
  appletArgs << Qt::Variant.new(args.arg(i))
176
 
end
177
 
 
178
 
view = FullView.new( formfactor, location )
179
 
# At this point arg(0) is always set
180
 
view.addApplet( args.arg(0), appletArgs )
181
 
view.show
182
 
 
183
 
action = KDE::StandardAction.quit(app, SLOT(:quit), view)
184
 
view.addAction(action)
185
 
 
186
 
if args.isSet("pixmapcache")
187
 
  puts "setting pixmap cache to #{args.getOption("pixmapcache")}"
188
 
  Qt::PixmapCache.cacheLimit = args.getOption("pixmapcache").to_i
189
 
end
190
 
 
191
 
app.exec
192
 
 
193