~kubuntu-members/korundum/4.11

« back to all changes in this revision

Viewing changes to plasma/examples/applets/analog-clock/clockapplet.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 (C) 2007-2008 by Riccardo Iaconelli <riccardo@kde.org>      *
4
 
 *   Copyright (C) 2007-2008 by Sebastian Kuegler <sebas@kde.org>          *
5
 
 *                                                                         *
6
 
 *   This program is free software; you can redistribute it and/or modify  *
7
 
 *   it under the terms of the GNU General Public License as published by  *
8
 
 *   the Free Software Foundation; either version 2 of the License, or     *
9
 
 *   (at your option) any later version.                                   *
10
 
 *                                                                         *
11
 
 *   This program is distributed in the hope that it will be useful,       *
12
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 
 *   GNU General Public License for more details.                          *
15
 
 *                                                                         *
16
 
 *   You should have received a copy of the GNU General Public License     *
17
 
 *   along with this program; if not, write to the                         *
18
 
 *   Free Software Foundation, Inc.,                                       *
19
 
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
20
 
 ***************************************************************************/
21
 
=end
22
 
 
23
 
class ClockApplet < Plasma::Applet
24
 
  attr_accessor :currentTimezone
25
 
 
26
 
  slots :configAccepted, 
27
 
        'showCalendar(QGraphicsSceneMouseEvent *)',
28
 
        'currentTimezone=(QString)'
29
 
 
30
 
  def initialize(parent, args)
31
 
    super(parent, args)
32
 
    @calendar = nil
33
 
    @currentTimezone = "Local"
34
 
 
35
 
    @calendarUi = Ui::Calendar.new
36
 
    @timezonesUi = Ui::TimezonesConfig.new
37
 
    @clicked = Qt::Point.new
38
 
    @timeZones = []
39
 
  end
40
 
 
41
 
  def updateToolTipContent()
42
 
  end
43
 
 
44
 
  def createConfigurationInterface(parent)
45
 
    createClockConfigurationInterface(parent)
46
 
 
47
 
    widget = Qt::Widget.new
48
 
    @timezonesUi.setupUi(widget)
49
 
 
50
 
    parent.addPage(widget, KDE.i18n("Time Zones"), icon())
51
 
 
52
 
    @timezonesUi.localTimeZone.checked = localTimezone?
53
 
    @timezonesUi.timeZones.setSelected(@currentTimezone, true)
54
 
    @timezonesUi.timeZones.enabled = !localTimezone?
55
 
 
56
 
    parent.buttons = KDE::Dialog::Ok | KDE::Dialog::Cancel | KDE::Dialog::Apply
57
 
    connect(parent, SIGNAL(:applyClicked), self, SLOT(:configAccepted))
58
 
    connect(parent, SIGNAL(:okClicked), self, SLOT(:configAccepted))
59
 
  end
60
 
 
61
 
  def createClockConfigurationInterface(parent)
62
 
  end
63
 
 
64
 
  def clockConfigAccepted()
65
 
  end
66
 
 
67
 
  def configAccepted()
68
 
    cg = config()
69
 
 
70
 
    @timeZones = @timezonesUi.timeZones.selection()
71
 
    cg.writeEntry("timeZones", @timeZones)
72
 
 
73
 
    newTimezone = localTimezone()
74
 
 
75
 
    if !@timezonesUi.localTimeZone.checked? && !@timeZones.empty?
76
 
        newTimezone = @timeZones[0]
77
 
    end
78
 
 
79
 
    changeEngineTimezone(@currentTimezone, newTimezone)
80
 
 
81
 
    @currentTimezone = newTimezone
82
 
    cg.writeEntry("currentTimezone", newTimezone)
83
 
 
84
 
    clockConfigAccepted()
85
 
 
86
 
    constraintsEvent(Plasma::SizeConstraint)
87
 
    update()
88
 
    emit configNeedsSaving
89
 
  end
90
 
 
91
 
  def changeEngineTimezone(oldTimezone, newTimezone)
92
 
  end
93
 
 
94
 
  def mousePressEvent(event)
95
 
    if event.buttons == Qt::LeftButton
96
 
      @clicked = scenePos.toPoint
97
 
      event.accepted = true
98
 
        return
99
 
    end
100
 
 
101
 
    super(event)
102
 
  end
103
 
 
104
 
  def mouseReleaseEvent(event)
105
 
    if (@clicked - scenePos.toPoint).manhattanLength <
106
 
        KDE::GlobalSettings.dndEventDelay()
107
 
        showCalendar(event)
108
 
    end
109
 
  end
110
 
 
111
 
  def showCalendar(event)
112
 
    if @calendar == 0
113
 
      @calendar = Plasma::Dialog.new
114
 
      @calendarUi.setupUi(@calendar)
115
 
      @calendar.setWindowFlags(Qt::Popup)
116
 
      @calendar.adjustSize
117
 
    end
118
 
 
119
 
    if @calendar.visible?
120
 
      @calendar.hide
121
 
    else
122
 
      data = dataEngine("time").query(@currentTimezone)
123
 
      @calendarUi.kdatepicker.date = data["Date"].toDate
124
 
      @calendar.move(popupPosition(@calendar.sizeHint))
125
 
      @calendar.show
126
 
    end
127
 
  end
128
 
 
129
 
  def localTimezone?
130
 
    return @currentTimezone == localTimezone()
131
 
  end
132
 
 
133
 
  def localTimezone()
134
 
    return "Local"
135
 
  end
136
 
end