~mutse-young/chinese-calendar/trunk

« back to all changes in this revision

Viewing changes to chinesecalendar.cpp

  • Committer: Shine Huang
  • Date: 2013-01-29 05:34:16 UTC
  • Revision ID: 22430571@qq.com-20130129053416-r6m7s65294nlyq5y
add indicator support

Show diffs side-by-side

added added

removed removed

Lines of Context:
383
383
//    Atom atom_task = XInternAtom(QX11Info::display (),"_NET_WM_STATE_SKIP_TASKBAR",False);
384
384
//    Atom atom =  XInternAtom(dis,"_NET_WM_STATE",False);
385
385
//    XChangeProperty(dis,winId(),atom,XA_ATOM,32,PropModeAppend,(unsigned char *)&atom_task,1);
 
386
 
 
387
    this->createTray();
386
388
}
387
389
 
388
390
ChineseCalendar::~ChineseCalendar()
390
392
  delete mycalendat;
391
393
}
392
394
 
 
395
void ChineseCalendar::createTray()
 
396
{
 
397
    this->actionShow = new QAction(tr("隐藏/显示"), this);
 
398
    connect(actionShow, SIGNAL(triggered()), this, SLOT(showOrHide()));
 
399
 
 
400
    this->actionStaysOnTop = new QAction(tr("总在最前"), this);
 
401
    this->actionStaysOnTop->setCheckable(true);
 
402
    connect(actionStaysOnTop, SIGNAL(triggered()), this, SLOT(setMode()));
 
403
 
 
404
    this->actionStaysOnBottom = new QAction(tr("总在最后"), this);
 
405
    this->actionStaysOnBottom->setCheckable(true);
 
406
    connect(actionStaysOnBottom, SIGNAL(triggered()), this, SLOT(setMode()));
 
407
 
 
408
    this->actionStaysNormal = new QAction(tr("普通模式"), this);
 
409
    this->actionStaysNormal->setCheckable(true);
 
410
    this->actionStaysNormal->setChecked(true);
 
411
    connect(actionStaysNormal, SIGNAL(triggered()), this, SLOT(setMode()));
 
412
 
 
413
    this->ag = new QActionGroup(this);
 
414
    this->ag->addAction(actionStaysOnTop);
 
415
    this->ag->addAction(actionStaysOnBottom);
 
416
    this->ag->addAction(actionStaysNormal);
 
417
 
 
418
    this->actionQuit = new QAction(tr("退出程序"), this);
 
419
    connect(actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));
 
420
 
 
421
    this->trayMenu = new QMenu(this);
 
422
    this->trayMenu->addAction(actionShow);
 
423
    this->trayMenu->addSeparator();
 
424
    this->trayMenu->addAction(actionStaysOnTop);
 
425
    this->trayMenu->addAction(actionStaysOnBottom);
 
426
    this->trayMenu->addAction(actionStaysNormal);
 
427
    this->trayMenu->addSeparator();
 
428
    this->trayMenu->addAction(actionQuit);
 
429
 
 
430
    this->trayIcon = new QSystemTrayIcon(this);
 
431
    this->trayIcon->setIcon(QIcon(":/img/chinesecalendar.png"));
 
432
    this->trayIcon->setContextMenu(trayMenu);
 
433
    this->trayIcon->show();
 
434
}
 
435
 
393
436
void ChineseCalendar::paintEvent(QPaintEvent *)
394
437
{
395
438
    QPainter painter(this);
749
792
        YearSelect->setDate(selectedDate.addYears(1));
750
793
}
751
794
 
 
795
void ChineseCalendar::showOrHide()
 
796
{
 
797
    if(this->isHidden())
 
798
    {
 
799
        this->show();
 
800
    }else
 
801
        this->hide();
 
802
}
 
803
 
 
804
void ChineseCalendar::setMode()
 
805
{
 
806
    if(this->actionStaysOnTop->isChecked())
 
807
    {
 
808
        this->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
 
809
        this->show();
 
810
    } else if(this->actionStaysOnBottom->isChecked())
 
811
    {
 
812
        this->setWindowFlags(Qt::WindowStaysOnBottomHint | Qt::FramelessWindowHint);
 
813
        this->show();
 
814
    } else
 
815
    {
 
816
        this->setWindowFlags(Qt::FramelessWindowHint);
 
817
        this->show();
 
818
    }
 
819
}