3 * Copyright 2007 Frerich Raabe <raabe@kde.org>
4 * Copyright 2007 Aaron Seigo <aseigo@kde.org
6 * Translated to Ruby by Richard Dale
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
32 require 'plasma_applet'
34 class FullView < Qt::GraphicsView
35 slots 'sceneRectChanged(QRectF)',
36 'resizeEvent(QResizeEvent)'
38 def initialize(ff = "planar", loc = "floating", parent = nil)
40 @formfactor = Plasma::Planar
41 @location = Plasma::Floating
44 @corona = Plasma::Corona.new
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
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
66 @location = Plasma::TopEdge
68 @location = Plasma::BottomEdge
70 @location = Plasma::RightEdge
72 @location = Plasma::LeftEdge
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)
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)
90 setSceneRect(@applet.geometry)
91 setWindowTitle(@applet.name)
92 setWindowIcon(Qt::Icon.new(KDE::SmallIcon(@applet.icon)))
95 def resizeEvent(event)
101 # The applet always keeps its aspect ratio, so let's respect it.
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
112 newWidth = newPossibleWidth
113 newHeight = newWidth / ratio
116 newWidth = size.width
117 newHeight = size.height
120 @containment.resize(Qt::SizeF.new(size()))
121 @applet.resize(Qt::SizeF.new(newWidth, newHeight))
124 def sceneRectChanged(rect)
126 setSceneRect(@applet.geometry)
131 description = I18N_NOOP( "Run Plasma applets in their own window" )
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" ),
140 KDE::CmdLineArgs.init( ARGV, aboutData )
142 options = KDE::CmdLineOptions.new
144 options.add( "formfactor <name>", KDE::ki18n( "The formfactor to use (horizontal, vertical, mediacenter or planar)" ), "planar")
146 options.add( "location <name>", KDE::ki18n( "The location constraint to start the Containment with (floating, desktop, fullscreen, top, bottom, left, right)" ), "floating")
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 )
153 app = KDE::Application.new
155 args = KDE::CmdLineArgs.parsedArgs
158 KDE::CmdLineArgs.usageError(KDE::i18n("No applet name specified"))
161 formfactor = "planar"
162 if args.isSet("formfactor")
163 puts "setting FormFactor to #{args.getOption("formfactor")}"
164 formfactor = args.getOption("formfactor")
167 location = "floating"
168 if args.isSet("location")
169 puts "setting Location to #{args.getOption("location")}"
170 location = args.getOption("location")
174 for i in 1...args.count do
175 appletArgs << Qt::Variant.new(args.arg(i))
178 view = FullView.new( formfactor, location )
179 # At this point arg(0) is always set
180 view.addApplet( args.arg(0), appletArgs )
183 action = KDE::StandardAction.quit(app, SLOT(:quit), view)
184 view.addAction(action)
186 if args.isSet("pixmapcache")
187 puts "setting pixmap cache to #{args.getOption("pixmapcache")}"
188 Qt::PixmapCache.cacheLimit = args.getOption("pixmapcache").to_i