~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/widgets/osdpretty.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "ui_osdpretty.h"
20
20
 
21
21
 
 
22
#include <QApplication>
 
23
#include <QBitmap>
22
24
#include <QColor>
 
25
#include <QDesktopWidget>
 
26
#include <QLayout>
 
27
#include <QMouseEvent>
23
28
#include <QPainter>
24
 
#include <QLayout>
25
 
#include <QApplication>
26
 
#include <QDesktopWidget>
27
29
#include <QSettings>
28
 
#include <QMouseEvent>
29
30
#include <QTimer>
30
 
#include <QBitmap>
31
31
#include <QTimeLine>
32
32
 
33
33
#include <QtDebug>
59
59
    background_color_(kPresetBlue),
60
60
    background_opacity_(0.85),
61
61
    popup_display_(0),
 
62
    font_(QFont()),
 
63
    disable_duration_(false),
62
64
    timeout_(new QTimer(this)),
63
65
    fading_enabled_(false),
64
 
    fader_(new QTimeLine(300, this))
 
66
    fader_(new QTimeLine(300, this)),
 
67
    toggle_mode_(false)
65
68
{
66
69
  Qt::WindowFlags flags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint |
67
70
                          Qt::X11BypassWindowManagerHint;
115
118
  int margin = l->margin() + kDropShadowSize;
116
119
  l->setMargin(margin);
117
120
 
118
 
  Load();
 
121
  // Get current screen resolution
 
122
  QRect screenResolution = QApplication::desktop()->screenGeometry();
 
123
  // Leave 200 px for icon
 
124
  ui_->summary->setMaximumWidth(screenResolution.width()-200);
 
125
  ui_->message->setMaximumWidth(screenResolution.width()-200);
 
126
  // Set maximum size for the OSD, a little margin here too
 
127
  setMaximumSize(screenResolution.width()-100,screenResolution.height()-100);
 
128
 
 
129
  // Don't load settings here, they will be reloaded anyway on creation
119
130
}
120
131
 
121
132
OSDPretty::~OSDPretty() {
138
149
  background_opacity_ = s.value("background_opacity", 0.85).toDouble();
139
150
  popup_display_ = s.value("popup_display", -1).toInt();
140
151
  popup_pos_ = s.value("popup_pos", QPoint(0, 0)).toPoint();
 
152
  font_.fromString(s.value("font", "Verdana,9,-1,5,50,0,0,0,0,0").toString());
 
153
  disable_duration_ = s.value("disable_duration", false).toBool();
141
154
 
 
155
  set_font(font());
142
156
  set_foreground_color(foreground_color());
143
157
}
144
158
 
227
241
 
228
242
  if (isVisible())
229
243
    Reposition();
230
 
 
231
 
  if (isVisible() && mode_ == Mode_Popup)
232
 
    timeout_->start(); // Restart the timer
 
244
}
 
245
 
 
246
// Set the desired message and then show the OSD
 
247
void OSDPretty::ShowMessage(const QString& summary, const QString& message,
 
248
                            const QImage& image) {
 
249
  SetMessage(summary, message, image);
 
250
 
 
251
  if (isVisible() && mode_ == Mode_Popup) {
 
252
    // The OSD is already visible, toggle or restart the timer
 
253
    if (toggle_mode()) {
 
254
      set_toggle_mode(false);
 
255
      // If timeout is disabled, timer hadn't been started
 
256
      if (!disable_duration())
 
257
        timeout_->stop();
 
258
      hide();
 
259
    } else {
 
260
      if (!disable_duration())
 
261
        timeout_->start(); // Restart the timer
 
262
    }
 
263
  } else {
 
264
    if (toggle_mode())
 
265
      set_toggle_mode(false);
 
266
    // The OSD is not visible, show it
 
267
    show();
 
268
  }
233
269
}
234
270
 
235
271
void OSDPretty::showEvent(QShowEvent* e) {
243
279
    fader_->setDirection(QTimeLine::Forward);
244
280
    fader_->start(); // Timeout will be started in FaderFinished
245
281
  }
246
 
  else if (mode_ == Mode_Popup)
247
 
    timeout_->start();
 
282
  else if (mode_ == Mode_Popup) {
 
283
    if (!disable_duration())
 
284
      timeout_->start();
 
285
    // Ensures it is above when showing the preview
 
286
    raise();
 
287
  }
248
288
}
249
289
 
250
290
void OSDPretty::setVisible(bool visible) {
259
299
void OSDPretty::FaderFinished() {
260
300
  if (fader_->direction() == QTimeLine::Backward)
261
301
    hide();
262
 
  else if (mode_ == Mode_Popup)
 
302
  else if (mode_ == Mode_Popup && !disable_duration())
263
303
    timeout_->start();
264
304
}
265
305
 
401
441
    popup_pos_ = current_pos();
402
442
  }
403
443
}
 
444
 
 
445
void OSDPretty::set_font(QFont font) {
 
446
  font_ = font;
 
447
 
 
448
  // Update the UI
 
449
  ui_->summary->setFont(font);
 
450
  ui_->message->setFont(font);
 
451
  // Now adjust OSD size so everything fits
 
452
  ui_->verticalLayout->activate();
 
453
  resize(sizeHint());
 
454
  // Update the position after font change
 
455
  Reposition();
 
456
}