Advertisement
Guest User

Untitled

a guest
Oct 4th, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include "joker.h"
  2.  
  3. joker::joker(QObject *parent) :
  4.     QObject(parent)
  5. {
  6.     window = new gui;
  7.     hide_timer = new QTimer;
  8.     is_msg_showing = false;
  9.     msg_pull = new QQueue<QString>;
  10.  
  11.     window->setWindowFlags(Qt::Widget | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
  12.     window->setParent(0);
  13.     window->setAttribute(Qt::WA_NoSystemBackground, true);
  14.     window->setAttribute(Qt::WA_TranslucentBackground, true);
  15.     // window->setAttribute(Qt::WA_PaintOnScreen);
  16.  
  17.     QLabel* label = window->findChild<QLabel*>("label");
  18.     QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect(this);
  19.     effect->setBlurRadius(0);
  20.     effect->setColor(QColor("#424242"));
  21.     effect->setOffset(3, 2);
  22.     label->setGraphicsEffect(effect);
  23.  
  24.     QObject::connect(hide_timer, SIGNAL(timeout()), this, SLOT(hide_window()));
  25. }
  26.  
  27. joker::~joker()
  28. {
  29.     delete window;
  30.     delete hide_timer;
  31. }
  32.  
  33. void joker::start()
  34. {
  35.     show_msg("test");
  36. }
  37.  
  38. void joker::show_window()
  39. {
  40.     if (window->isHidden())
  41.         window->show();
  42. }
  43.  
  44. void joker::hide_window()
  45. {
  46.     if (!window->isHidden())
  47.         window->hide();
  48. }
  49.  
  50. void joker::center_window()
  51. {
  52.     window->adjustSize();
  53.     window->move(QApplication::desktop()->screen()->rect().center() - window->rect().center());
  54. }
  55.  
  56. void joker::show_msg(QString msg)
  57. {
  58.     if (msg.length() == 0)
  59.         return;
  60.  
  61.     int duration = msg.length() * 80;
  62.     show_msg(msg, duration);
  63. }
  64.  
  65. void joker::show_msg(QString msg, int dur)
  66. {
  67.     QLabel* label = window->findChild<QLabel*>("label");
  68.     label->setText(msg);
  69.     center_window();
  70.     show_window();
  71.     hide_timer->start(dur);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement