WidgetNotificationPrivate( WidgetNotification* pParent ): m_pNotificationWidget(NULL), m_pNotificationUi(NULL) { QImage shadow_edge(":osd_shadow_edge.png"); QImage shadow_corner(":osd_shadow_corner.png"); for ( int i = 0 ; i < scCornerNumber; ++i ) { QTransform rotation = QTransform().rotate(90 * i); shadowsEdges.push_back(QPixmap::fromImage(shadow_edge.transformed(rotation))); shadowsCorners.push_back(QPixmap::fromImage(shadow_corner.transformed(rotation))); } }
OSDPretty::OSDPretty(Mode mode, QWidget* parent) : QWidget(parent), ui_(new Ui_OSDPretty), mode_(mode), background_color_(kPresetBlue), background_opacity_(0.85), popup_display_(0), font_(QFont()), disable_duration_(false), timeout_(new QTimer(this)), fading_enabled_(false), fader_(new QTimeLine(300, this)), toggle_mode_(false) { Qt::WindowFlags flags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint; setWindowFlags(flags); setAttribute(Qt::WA_TranslucentBackground, true); setAttribute(Qt::WA_X11NetWmWindowTypeNotification, true); setAttribute(Qt::WA_ShowWithoutActivating, true); ui_->setupUi(this); #ifdef Q_OS_WIN32 // Don't show the window in the taskbar. Qt::ToolTip does this too, but it // adds an extra ugly shadow. int ex_style = GetWindowLong(winId(), GWL_EXSTYLE); ex_style |= WS_EX_NOACTIVATE; SetWindowLong(winId(), GWL_EXSTYLE, ex_style); #endif // Mode settings switch (mode_) { case Mode_Popup: setCursor(QCursor(Qt::ArrowCursor)); break; case Mode_Draggable: setCursor(QCursor(Qt::OpenHandCursor)); break; } // Timeout timeout_->setSingleShot(true); timeout_->setInterval(5000); connect(timeout_, SIGNAL(timeout()), SLOT(hide())); ui_->icon->setMaximumSize(kMaxIconSize, kMaxIconSize); // Fader connect(fader_, SIGNAL(valueChanged(qreal)), SLOT(FaderValueChanged(qreal))); connect(fader_, SIGNAL(finished()), SLOT(FaderFinished())); #ifdef Q_OS_WIN32 set_fading_enabled(true); #endif // Load the show edges and corners QImage shadow_edge(":osd_shadow_edge.png"); QImage shadow_corner(":osd_shadow_corner.png"); for (int i = 0; i < 4; ++i) { QTransform rotation = QTransform().rotate(90 * i); shadow_edge_[i] = QPixmap::fromImage(shadow_edge.transformed(rotation)); shadow_corner_[i] = QPixmap::fromImage(shadow_corner.transformed(rotation)); } background_ = QPixmap(":osd_background.png"); // Set the margins to allow for the drop shadow QBoxLayout* l = static_cast<QBoxLayout*>(layout()); int margin = l->margin() + kDropShadowSize; l->setMargin(margin); // Get current screen resolution QRect screenResolution = QApplication::desktop()->screenGeometry(); // Leave 200 px for icon ui_->summary->setMaximumWidth(screenResolution.width() - 200); ui_->message->setMaximumWidth(screenResolution.width() - 200); // Set maximum size for the OSD, a little margin here too setMaximumSize(screenResolution.width() - 100, screenResolution.height() - 100); // Don't load settings here, they will be reloaded anyway on creation }