[Kde-bindings] KDE/kdebindings/ruby/plasma
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Thu Aug 7 20:19:12 UTC 2008
SVN commit 843771 by rdale:
* Add two versions of the clock applet
* plasma_applet_ruby_clock uses the ScriptEngine api and is packaged as a
plasmoid. It can be installed by typing the following command in the
examples/applets directory:
$ plasmapkg --install plasma_applet_ruby_clock --type plasmoid
* analog-clock uses the C++ plugin api. Normally Ruby applets should be
written using the script engine api, and this example is only included
to show how the two apis differ. The clocks are functionally identical.
CCMAIL: kde-bindings at kde.org
M +10 -0 ChangeLog
M +11 -9 examples/applets/analog-clock/CMakeLists.txt
M +8 -2 examples/applets/analog-clock/calendar.ui
M +33 -62 examples/applets/analog-clock/clock.rb
A examples/applets/analog-clock/clockConfig.ui
A examples/applets/analog-clock/clockapplet.rb
D examples/applets/analog-clock/contents (directory)
D examples/applets/analog-clock/metadata.desktop
A examples/applets/analog-clock/plasma-applet-ruby-analogclock.desktop
D examples/applets/analog-clock/plasma-ruby-clock-default.desktop
A examples/applets/analog-clock/timezonesConfig.ui
A examples/applets/plasma_applet_ruby_clock (directory)
A examples/applets/plasma_applet_ruby_clock/contents (directory)
A examples/applets/plasma_applet_ruby_clock/contents/code (directory)
A examples/applets/plasma_applet_ruby_clock/contents/code/analog_clock_config.rb
A examples/applets/plasma_applet_ruby_clock/contents/code/calendar.rb
A examples/applets/plasma_applet_ruby_clock/contents/code/clockapplet.rb
A examples/applets/plasma_applet_ruby_clock/contents/code/main.rb
A examples/applets/plasma_applet_ruby_clock/contents/code/timezones_config.rb
A examples/applets/plasma_applet_ruby_clock/contents/ui (directory)
A examples/applets/plasma_applet_ruby_clock/contents/ui/analog_clock_config.ui
A examples/applets/plasma_applet_ruby_clock/contents/ui/calendar.ui
A examples/applets/plasma_applet_ruby_clock/contents/ui/timezonesConfig.ui
A examples/applets/plasma_applet_ruby_clock/metadata.desktop
M +2 -1 src/lib/KDE/plasma.rb
--- trunk/KDE/kdebindings/ruby/plasma/ChangeLog #843770:843771
@@ -8,7 +8,17 @@
* Special case Plasma::Applet#id so it doesn't get a Ruby warning.
* In PlasmaScriptengineRuby::Applet the module name wasn't being derived
correctly from the Package path
+* Add two versions of the clock applet
+ * plasma_applet_ruby_clock uses the ScriptEngine api and is packaged as a
+ plasmoid. It can be installed by typing the following command in the
+ examples/applets directory:
+ $ plasmapkg --install plasma_applet_ruby_clock --type plasmoid
+
+ * analog-clock uses the C++ plugin api. Normally Ruby applets should be
+ written using the script engine api, and this example is only included
+ to show how the two apis differ. The clocks are functionally identical.
+
2008-08-06 Richard Dale <richard.j.dale at gmail.com>
* Add some fixes for the new Plasma::Frame and Plasma::Slider widgets
--- trunk/KDE/kdebindings/ruby/plasma/examples/applets/analog-clock/CMakeLists.txt #843770:843771
@@ -1,21 +1,23 @@
FIND_PACKAGE (RUBY REQUIRED)
-SET(UI_CLOCKCONFIG ${CMAKE_CURRENT_SOURCE_DIR}/analog_clock_config.ui)
+SET(UI_CLOCKCONFIG ${CMAKE_CURRENT_SOURCE_DIR}/clockConfig.ui)
SET(UI_CALENDAR ${CMAKE_CURRENT_SOURCE_DIR}/calendar.ui)
+SET(UI_TIMEZONESCONFIG ${CMAKE_CURRENT_SOURCE_DIR}/timezonesConfig.ui)
FIND_PROGRAM(RBUIC4 rbuic4 PATHS ${BIN_INSTALL_DIR})
if(RBUIC4)
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/analog_clock_config.rb COMMAND ${RBUIC4} ${UI_CLOCKCONFIG} -o ${CMAKE_CURRENT_BINARY_DIR}/analog_clock_config.rb COMMENT "Generating analog_clock_config.rb")
- ADD_CUSTOM_TARGET(analog_clock_config ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/analog_clock_config.rb)
+ ADD_CUSTOM_TARGET(clockConfig ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/analog_clock_config.rb)
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/calendar.rb COMMAND ${RBUIC4} ${UI_CALENDAR} -o ${CMAKE_CURRENT_BINARY_DIR}/calendar.rb COMMENT "Generating calendar.rb")
ADD_CUSTOM_TARGET(calendar ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/calendar.rb)
+ ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/timezones_config.rb COMMAND ${RBUIC4} ${UI_TIMEZONESCONFIG} -o ${CMAKE_CURRENT_BINARY_DIR}/timezones_config.rb COMMENT "Generating timezones_config.rb")
+ ADD_CUSTOM_TARGET(timezonesConfig ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/timezones_config.rb)
- include_directories( ${RUBY_INCLUDE_PATH} )
-
- install(FILES plasma-ruby-clock-default.desktop DESTINATION ${SERVICES_INSTALL_DIR})
-
- install(FILES clock.rb DESTINATION ${DATA_INSTALL_DIR}/plasma_ruby_analog_clock)
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/analog_clock_config.rb DESTINATION ${DATA_INSTALL_DIR}/plasma_ruby_analog_clock)
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/calendar.rb DESTINATION ${DATA_INSTALL_DIR}/plasma_ruby_analog_clock)
+ install(FILES plasma-applet-ruby-analogclock.desktop DESTINATION ${SERVICES_INSTALL_DIR})
+ install(FILES clock.rb DESTINATION ${DATA_INSTALL_DIR}/plasma_applet_ruby_clock)
+ install(FILES clockapplet.rb DESTINATION ${DATA_INSTALL_DIR}/plasma_applet_ruby_clock)
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/analog_clock_config.rb DESTINATION ${DATA_INSTALL_DIR}/plasma_applet_ruby_clock)
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/calendar.rb DESTINATION ${DATA_INSTALL_DIR}/plasma_applet_ruby_clock)
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/timezones_config.rb DESTINATION ${DATA_INSTALL_DIR}/plasma_applet_ruby_clock)
else(RBUIC4)
MESSAGE(STATUS "rbuic4 not found, ruby-clock will not created")
endif(RBUIC4)
--- trunk/KDE/kdebindings/ruby/plasma/examples/applets/analog-clock/calendar.ui #843770:843771
@@ -5,14 +5,20 @@
<rect>
<x>0</x>
<y>0</y>
- <width>274</width>
+ <width>276</width>
<height>255</height>
</rect>
</property>
<property name="styleSheet" >
- <string/>
+ <string notr="true" />
</property>
<layout class="QVBoxLayout" >
+ <property name="spacing" >
+ <number>0</number>
+ </property>
+ <property name="margin" >
+ <number>0</number>
+ </property>
<item>
<widget class="KDatePicker" name="kdatepicker" >
<property name="autoFillBackground" >
--- trunk/KDE/kdebindings/ruby/plasma/examples/applets/analog-clock/clock.rb #843770:843771
@@ -23,15 +23,16 @@
=end
require 'plasma_applet'
-require 'analog_clock_config.rb'
+require 'analog_clock_config'
+require 'timezones_config'
require 'calendar'
+require 'clockapplet'
-module PlasmaRubyAnalogClock
+module PlasmaAppletRubyClock
-class Clock < Plasma::Containment
+class Clock < ClockApplet
slots :moveSecondHand, :configAccepted,
- 'showCalendar(QGraphicsSceneMouseEvent *)',
'dataUpdated(QString, Plasma::DataEngine::Data)'
def initialize(parent, args)
@@ -82,9 +83,17 @@
if constraints.to_i & Plasma::FormFactorConstraint.to_i
setBackgroundHints(NoBackground)
end
+
+ if constraints.to_i & Plasma::SizeConstraint.to_i
+ @theme.resize(size())
+ end
end
def shape
+ if @theme.hasElement("hint-square-clock")
+ return super
+ end
+
path = Qt::PainterPath.new
path.addEllipse(boundingRect().adjusted(-2, -2, 2, 2))
return path
@@ -106,23 +115,17 @@
update()
end
- def createConfigurationInterface(parent)
+ def createClockConfigurationInterface(parent)
# TODO: Make the size settable
widget = Qt::Widget.new
@ui.setupUi(widget)
- parent.buttons = KDE::Dialog::Ok | KDE::Dialog::Cancel | KDE::Dialog::Apply
- connect(parent, SIGNAL(:applyClicked), self, SLOT(:configAccepted))
- connect(parent, SIGNAL(:okClicked), self, SLOT(:configAccepted));
- parent.addPage(widget, parent.windowTitle, icon)
+ parent.addPage(widget, KDE.i18n("General"), icon)
- @ui.timeZones.setSelected(@timezone, true)
- @ui.timeZones.enabled = @timezone != "Local"
- @ui.localTimeZone.checked = @timezone == "Local"
@ui.showTimeStringCheckBox.checked = @showTimeString
@ui.showSecondHandCheckBox.checked = @showSecondHand
end
- def configAccepted()
+ def clockConfigAccepted()
cg = config()
@showTimeString = @ui.showTimeStringCheckBox.checked?
@showSecondHand = @ui.showSecondHandCheckBox.checked?
@@ -130,31 +133,24 @@
cg.writeEntry("showTimeString", @showTimeString)
cg.writeEntry("showSecondHand", @showSecondHand)
update()
- tzs = @ui.timeZones.selection
- if @ui.localTimeZone.checkState == Qt::Checked
- dataEngine("time").disconnectSource(@timezone, self)
- @timezone = "Local"
- cg.writeEntry("timezone", @timezone)
- elsif tzs.length > 0
- # TODO: support multiple timezones
- tz = tzs[0]
- if tz != @timezone
- dataEngine("time").disconnectSource(@timezone, self)
- @timezone = tz;
- cg.writeEntry("timezone", @timezone)
- end
- elsif @timezone != "Local"
- dataEngine("time").disconnectSource(@timezone, self)
- @timezone = "Local"
- cg.writeEntry("timezone", @timezone)
- end
-
+ dataEngine("time").disconnectSource(currentTimezone(), self)
connectToEngine
+
constraintsEvent(Plasma::AllConstraints)
emit configNeedsSaving
end
+ def changeEngineTimezone(oldTimezone, newTimezone)
+ dataEngine("time").disconnectSource(oldTimezone, self)
+ timeEngine = dataEngine("time")
+ if @showSecondHand
+ timeEngine.connectSource(newTimezone, self, 500)
+ else
+ timeEngine.connectSource(newTimezone, self, 6000, Plasma::AlignToMinute)
+ end
+ end
+
def moveSecondHand
update
end
@@ -168,12 +164,15 @@
p.rotate(rotation)
p.translate(-elementRect.width / 2, -(@theme.elementRect("clockFace").center.y - elementRect.top))
@theme.paint(p, Qt::RectF.new(Qt::PointF.new(0.0, 0.0), elementRect.size), handName)
+
p.restore
end
def paintInterface(p, option, rect)
tempRect = Qt::RectF.new(0, 0, 0, 0)
+
boundSize = geometry.size
+
p.renderHint = Qt::Painter::SmoothPixmapTransform
minutes = 6.0 * @time.minute - 180
@@ -190,6 +189,7 @@
else
time = @time.toString("hh:mm")
end
+
textRect = Qt::Rect.new((rect.width/2 - fm.width(time) / 2),((rect.height / 2) - fm.xHeight * 4),
fm.width(time), fm.xHeight())
@@ -252,12 +252,11 @@
drawHand(p, seconds, "SecondHandShadow")
end
- p.translate(-1,-3);
+ p.translate(-1,-3)
end
drawHand(p, hours, "HourHand")
drawHand(p, minutes, "MinuteHand")
-
if @showSecondHand
drawHand(p, seconds, "SecondHand")
end
@@ -265,7 +264,6 @@
p.save
@theme.resize(boundSize)
elementSize = Qt::SizeF.new(@theme.elementSize("HandCenterScrew"))
-
tempRect.size = elementSize
p.translate(boundSize.width / 2.0 - elementSize.width / 2.0, boundSize.height / 2.0 - elementSize.height / 2.0)
@theme.paint(p, tempRect, "HandCenterScrew")
@@ -273,33 +271,6 @@
@theme.paint(p, Qt::RectF.new(rect), "Glass")
end
-
- def mousePressEvent(event)
- if event.buttons == Qt::LeftButton
- showCalendar(event)
- else
- event.ignore
- end
- end
-
- def showCalendar(event)
- if @calendar == 0
- @calendar = Plasma::Dialog.new
- @calendarUi.setupUi(@calendar)
- @calendar.setWindowFlags(Qt::Popup)
- @calendar.adjustSize
- end
-
- if @calendar.visible?
- @calendar.hide
- else
- data = dataEngine("time").query(@timezone)
- @calendarUi.kdatepicker.date = data["Date"].toDate
- @calendar.move(popupPosition(@calendar.sizeHint))
- @calendar.show
- end
- end
-
end
end
\ No newline at end of file
--- trunk/KDE/kdebindings/ruby/plasma/src/lib/KDE/plasma.rb #843770:843771
@@ -156,7 +156,8 @@
@dialog.setAttribute(Qt::WA_DeleteOnClose, true)
createConfigurationInterface(@dialog)
# TODO: would be nice to not show dialog if there are no pages added?
- connect(@dialog, SIGNAL(:finished), @nullManager, SLOT(:deleteLater))
+ # Don't connect to the deleteLater() slot in Ruby as it causes crashes
+ # connect(@dialog, SIGNAL(:finished), @nullManager, SLOT(:deleteLater))
# TODO: Apply button does not correctly work for now, so do not show it
@dialog.showButton(KDE::Dialog::Apply, false)
@dialog.show
More information about the Kde-bindings
mailing list