defuze.me
Client
|
00001 #include "schedulerwidget.hpp" 00002 #include "scheduler.hpp" 00003 00004 using namespace Scheduler; 00005 00006 SchedulerWidget::SchedulerWidget(SchedulerPlugin *scheduler, QWidget *parent) : 00007 ModuleWidget(parent), scheduler(scheduler) 00008 { 00009 setupUi(this); 00010 00011 this->setHorizontalHeader(); 00012 this->setVerticalHeader(); 00013 this->setGrid(); 00014 00015 this->connect(this, SIGNAL(clicked()), this, SLOT(gridClicked())); 00016 00017 SchedulerLayout->setContentsMargins(0, 0, 0, 0); 00018 } 00019 00020 QGridLayout *SchedulerWidget::getLayout() const 00021 { 00022 return SchedulerLayout; 00023 } 00024 00025 void SchedulerWidget::changeEvent(QEvent *e) 00026 { 00027 QWidget::changeEvent(e); 00028 switch (e->type()) { 00029 case QEvent::LanguageChange: 00030 retranslateUi(this); 00031 break; 00032 default: 00033 break; 00034 SchedulerLayout->update(); 00035 } 00036 } 00037 00038 void SchedulerWidget::mousePressEvent(QMouseEvent *) 00039 { 00040 emit clicked(); 00041 } 00042 00043 void SchedulerWidget::gridClicked() 00044 { 00045 this->scheduler->getEventWidget()->clear(); 00046 } 00047 00048 void SchedulerWidget::setHorizontalHeader() 00049 { 00050 QStringList days; 00051 days << tr("Monday") << tr("Tuesday") << tr("Wednesday") << tr("Thursday") << tr("Friday") << tr("Saturday") << tr("Sunday"); 00052 00053 for (int index = 0; index < days.size(); index += 1) 00054 { 00055 QLabel *day = new QLabel(days.at(index)); 00056 00057 day->setAlignment(Qt::AlignCenter); 00058 day->setStyleSheet("border: none; min-height: 28px; padding-bottom: 10px;"); 00059 00060 SchedulerLayout->addWidget(day, 0, index + 1, SCALE, 1); 00061 SchedulerLayout->setColumnMinimumWidth(index + 1, 0); 00062 SchedulerLayout->setColumnStretch(index + 1, 1); 00063 } 00064 } 00065 00066 void SchedulerWidget::setVerticalHeader() 00067 { 00068 for (int index = 0; index < 24; index += 1) 00069 { 00070 QLabel *time = new QLabel(QString().sprintf("%02d", index) + ":00"); 00071 00072 time->setStyleSheet((index == (24 - 1)) ? "border-bottom: 1px solid rgb(65, 65, 65); padding: 0 10px;": "padding: 0 10px;"); 00073 time->setAlignment(Qt::AlignTop); 00074 00075 SchedulerLayout->addWidget(time, (index * SCALE) + SCALE, 0, SCALE, 1); 00076 SchedulerLayout->setRowMinimumHeight((index * SCALE) + SCALE, 0); 00077 SchedulerLayout->setRowStretch((index * SCALE) + SCALE, 1); 00078 } 00079 } 00080 00081 void SchedulerWidget::setGrid() 00082 { 00083 for (int index = 0; index < 24 * SCALE; index += 1) 00084 { 00085 for (int subIndex = 0; subIndex < 7; subIndex += 1) 00086 { 00087 QLabel *content = new QLabel(" "); 00088 if ((index == (24 * SCALE - 1)) && (subIndex == (7 - 1))) 00089 { 00090 content->setStyleSheet(((index % SCALE) != 0) ? "border-bottom: 1px solid rgb(65, 65, 65); border-top: 1px solid rgb(50, 50, 50); border-right: 1px solid rgb(65, 65, 65);" : 00091 "border-bottom: 1px solid rgb(65, 65, 65); border-right: 1px solid rgb(65, 65, 65);"); 00092 } 00093 else if (index == (24 * SCALE - 1)) 00094 { 00095 content->setStyleSheet(((index % SCALE) != 0) ? "border-bottom: 1px solid rgb(65, 65, 65); border-top: 1px solid rgb(50, 50, 50);" : 00096 "border-bottom: 1px solid rgb(65, 65, 65);"); 00097 } 00098 else if (subIndex == (7 - 1)) 00099 { 00100 content->setStyleSheet(((index % SCALE) != 0) ? "border-right: 1px solid rgb(65, 65, 65); border-top: 1px solid rgb(50, 50, 50);" : 00101 "border-right: 1px solid rgb(65, 65, 65);"); 00102 } 00103 else if ((index % SCALE) != 0) 00104 { 00105 content->setStyleSheet("border-top: 1px solid rgb(50, 50, 50);"); 00106 } 00107 00108 content->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); 00109 00110 SchedulerLayout->addWidget(content, index + SCALE, subIndex + 1, 1, 1); 00111 SchedulerLayout->setRowMinimumHeight(index + SCALE, 0); 00112 SchedulerLayout->setRowStretch(index + SCALE, 1); 00113 } 00114 } 00115 } 00116 00117 void SchedulerWidget::displayEvent(EventModel *event) 00118 { 00119 int row = (event->getStartTime() * SCALE) / 60 + SCALE; 00120 int rowSpan = ((event->getDuration() * SCALE / 60) == 0 ) ? 1 : event->getDuration() * SCALE / 60; 00121 00122 this->SchedulerLayout->addWidget(event, row, event->getDay() + 1, rowSpan, 1); 00123 } 00124 00125 void SchedulerWidget::removeEvent(EventModel *event) 00126 { 00127 SchedulerLayout->removeWidget(event); 00128 SchedulerLayout->update(); 00129 }