/** * Initializes the main window object * Updates preferences * Checks whether database tables are exists * Adds a context menu and sets accepted drops * Moreover, registers signals and slots * @param parent Pointer to the super class of objects */ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->setCentralWidget(ui->textEdit_mainWindow_surface); updatePreferences(); db.transaction(); query.prepare("CREATE TABLE IF NOT EXISTS `password` ( " "`PasswordID` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " "`Password` TEXT NOT NULL UNIQUE );"); if ( query.exec() ) { db.commit(); qDebug() << "The table of the database exists"; } else { db.rollback(); qDebug() << "The table of the database does not exist"; qDebug() << query.lastError(); } addContextMenu(); ui->textEdit_mainWindow_surface->setAcceptDrops(false); setAcceptDrops(true); connect(this, SIGNAL(backgroundChanged()), this, SLOT(updatePreferences())); }
void ItemHandlerSpinboxRange::Handle (const QDomElement& item, QWidget *pwidget) { QGridLayout *lay = qobject_cast<QGridLayout*> (pwidget->layout ()); QLabel *label = new QLabel (XSD_->GetLabel (item)); label->setWordWrap (false); RangeWidget *widget = new RangeWidget (); XSD_->SetTooltip (widget, item); widget->setObjectName (item.attribute ("property")); widget->SetMinimum (item.attribute ("minimum").toInt ()); widget->SetMaximum (item.attribute ("maximum").toInt ()); const QVariant& value = XSD_->GetValue (item); widget->SetRange (value); connect (widget, SIGNAL (changed ()), this, SLOT (updatePreferences ())); widget->setProperty ("ItemHandler", QVariant::fromValue<QObject*> (this)); widget->setProperty ("SearchTerms", label->text ()); int row = lay->rowCount (); lay->addWidget (label, row, 0, Qt::AlignRight); lay->addWidget (widget, row, 1); }
void ItemHandlerColor::Handle (const QDomElement& item, QWidget *pwidget) { QGridLayout *lay = qobject_cast<QGridLayout*> (pwidget->layout ()); const QString& labelString = XSD_->GetLabel (item); QLabel *label = new QLabel (labelString); label->setWordWrap (false); ColorPicker *picker = new ColorPicker (labelString); picker->setObjectName (item.attribute ("property")); picker->SetCurrentColor (XSD_->GetValue (item).value<QColor> ()); connect (picker, SIGNAL (currentColorChanged (QColor)), this, SLOT (updatePreferences ())); picker->setProperty ("ItemHandler", QVariant::fromValue<QObject*> (this)); int row = lay->rowCount (); lay->setColumnMinimumWidth (0, 10); lay->setColumnStretch (0, 1); lay->setColumnStretch (1, 10); lay->addWidget (label, row, 0); lay->addWidget (picker, row, 1, Qt::AlignLeft); }
void ItemHandlerRadio::Handle (const QDomElement& item, QWidget *pwidget) { QGridLayout *lay = qobject_cast<QGridLayout*> (pwidget->layout ()); RadioGroup *group = new RadioGroup (XSD_); group->setObjectName (item.attribute ("property")); QDomElement option = item.firstChildElement ("option"); while (!option.isNull ()) { QRadioButton *button = new QRadioButton (XSD_->GetLabel (option)); button->setObjectName (option.attribute ("name")); group->AddButton (button, option.hasAttribute ("default") && option.attribute ("default") == "true"); option = option.nextSiblingElement ("option"); } QVariant value = XSD_->GetValue (item); connect (group, SIGNAL (valueChanged ()), this, SLOT (updatePreferences ())); QGroupBox *box = new QGroupBox (XSD_->GetLabel (item)); QVBoxLayout *layout = new QVBoxLayout (); box->setLayout (layout); layout->addWidget (group); group->setProperty ("ItemHandler", QVariant::fromValue<QObject*> (this)); lay->addWidget (box, lay->rowCount (), 0); }
/** * Opens the preferences dialog */ void MainWindow::on_actionSettings_triggered() { preference = new Preference(); connect(preference, SIGNAL(preferencesChanged()), this, SLOT(updatePreferences())); preference->setModal(true); preference->setAttribute(Qt::WA_DeleteOnClose, true); preference->exec(); }
//Mark an alarm for deletion void markDelete(int day, int hour, int minute) { for(int i=0; i<vectorAlarmTimes.size(); ++i) { if(vectorAlarmTimes.at(i).at(6) == day && vectorAlarmTimes.at(i).at(0) == hour && vectorAlarmTimes.at(i).at(1) == minute) { vectorAlarmTimes.at(i).at(7) = true; updatePreferences(); updateAlarmString(); } } }
void ItemHandlerMultiLine::Handle (const QDomElement& item, QWidget *pwidget) { QGridLayout *lay = qobject_cast<QGridLayout*> (pwidget->layout ()); QLabel *label = new QLabel (XSD_->GetLabel (item)); label->setWordWrap (false); const QVariant& value = XSD_->GetValue (item); QTextEdit *edit = new QTextEdit (); XSD_->SetTooltip (edit, item); edit->setPlainText (value.toStringList ().join ("\n")); edit->setObjectName (item.attribute ("property")); edit->setMinimumWidth (QApplication::fontMetrics () .width ("thisismaybeadefaultsetting")); connect (edit, SIGNAL (textChanged ()), this, SLOT (updatePreferences ())); edit->setProperty ("ItemHandler", QVariant::fromValue<QObject*> (this)); edit->setProperty ("SearchTerms", label->text ()); int row = lay->rowCount (); QString pos = item.attribute ("position"); if (pos == "bottom") { lay->addWidget (label, row, 0, Qt::AlignLeft); lay->addWidget (edit, row + 1, 0); } else if (pos == "right") { lay->addWidget (label, row, 0, Qt::AlignRight | Qt::AlignTop); lay->addWidget (edit, row, 1); } else if (pos == "left") { lay->addWidget (label, row, 1, Qt::AlignLeft | Qt::AlignTop); lay->addWidget (edit, row, 0); } else if (pos == "top") { lay->addWidget (edit, row, 0); lay->addWidget (label, row + 1, 0, Qt::AlignLeft); } else { lay->addWidget (label, row, 0, Qt::AlignRight | Qt::AlignTop); lay->addWidget (edit, row, 1); } lay->setContentsMargins (2, 2, 2, 2); }
void LightAlarm() { //TODO: Check/Debug if this can even run - one time alarm may have already been cleared/deleted by now int alarmID = Alarm.getTriggeredAlarmId(); int alarmIndex = checkDelete(alarmID); //do nothing if it was just deleted (in checkDelete()) if(alarmIndex == -2) { return; } lightFadeIn(vectorAlarmTimes.at(alarmIndex).at(0), vectorAlarmTimes.at(alarmIndex).at(1)); //delete alarm from the array if it is a one time alarm if(vectorAlarmTimes.at(alarmIndex).at(3) == true) { vectorAlarmTimes.erase(vectorAlarmTimes.begin() + alarmIndex); updatePreferences(); updateAlarmString(); } }
//Check if marked, if so delete the alarm from eeprom and alarmTimes //Returns 0 if deleted, -1 if not found, or the array index int checkDelete(AlarmID_t ID) { unsigned long currentTime = Time.now(); int hour = Time.hour(currentTime); int minute = Time.minute(currentTime); int alarmIndex = -1; for(int i=0; i<vectorAlarmTimes.size(); ++i) { if(vectorAlarmTimes.at(i).at(0) == hour && vectorAlarmTimes.at(i).at(1) == minute) { alarmIndex = i; if(vectorAlarmTimes.at(i).at(7)== true) { Alarm.free(ID); vectorAlarmTimes.erase(vectorAlarmTimes.begin() + i); updatePreferences(); updateAlarmString(); return -2; } } } return alarmIndex; }
void ItemHandlerSpinboxRange::Handle (const QDomElement& item, QWidget *pwidget) { QFormLayout *lay = qobject_cast<QFormLayout*> (pwidget->layout ()); QLabel *label = new QLabel (XSD_->GetLabel (item)); label->setWordWrap (false); RangeWidget *widget = new RangeWidget (); widget->setObjectName (item.attribute ("property")); widget->SetMinimum (item.attribute ("minimum").toInt ()); widget->SetMaximum (item.attribute ("maximum").toInt ()); QVariant value = XSD_->GetValue (item); widget->SetRange (value); connect (widget, SIGNAL (changed ()), this, SLOT (updatePreferences ())); widget->setProperty ("ItemHandler", QVariant::fromValue<QObject*> (this)); lay->addRow (label, widget); }
//TODO: Make sure no larger than array size 32 //Set an alarm according to the given parameters void setAlarm(int hour, int minute, int second, bool isOnce, bool light, bool sound, int dayOfWeek) { unsigned long currentTime = Time.now(); int currentDay = Time.weekday(currentTime); int currentHour = Time.hour(currentTime); int currentMinute = Time.minute(currentTime); int day2 = dayOfWeek; int hour2 = hour; int minute2 = minute; //Checks if duplicate marked for deletion exists, if so unmark delete for(int i=0; i<vectorAlarmTimes.size(); ++i) { if(vectorAlarmTimes.at(i).at(0) == hour && vectorAlarmTimes.at(i).at(1) == minute) { if(vectorAlarmTimes.at(i).at(7) == false) { return; } else if(vectorAlarmTimes.at(i).at(3) == isOnce && vectorAlarmTimes.at(i).at(4) == light && vectorAlarmTimes.at(i).at(5) == sound && vectorAlarmTimes.at(i).at(6) == dayOfWeek) { vectorAlarmTimes.at(i).at(7) = true; updateAlarmString(); return; } } } //Get the time a LightAlarm would go off (30 minutes early if light is enabled) if(light) { minute2 -= 30; if(minute2 < 0) { minute2 = 60 + minute2; hour2 -= 1; if(hour2 < 0) { hour2 = 23; day2 -= 1; if(day2 < 1) { day2 = 7; } } } //Check if there is enough time and handle accordingly bool enoughTime = true; currentMinute -= 30; if(currentMinute < 0) { currentMinute = 60 + currentMinute; currentHour -= 1; if(currentHour < 0) { currentHour = 23; currentDay -= 1; if(currentDay < 1) { currentDay = 7; } } } if(currentDay == day2 && currentHour >= hour2 && currentMinute >= minute2) { enoughTime = false; } if(!enoughTime) { lightFadeIn(hour, minute); } if(isOnce) { if(enoughTime) { if(dayOfWeek != -1) { Alarm.alarmOnce(day2, hour2, minute2, second, LightAlarm); } else { Alarm.alarmOnce(hour2, minute2, second, LightAlarm); } } } else { if(dayOfWeek != -1) { Alarm.alarmRepeat(day2, hour2, minute2, second, LightAlarm); } else { Alarm.alarmRepeat(hour2, minute2, second, LightAlarm); } } } //set a SoundAlarm if sound is enabled or if both sound and light are disabled if(sound || (!light && !sound)) { if(isOnce) { if(dayOfWeek != -1) { Alarm.alarmOnce(dayOfWeek, hour, minute, second, SoundAlarm); } else { Alarm.alarmOnce(hour, minute, second, SoundAlarm); } } else { if(dayOfWeek != -1) { Alarm.alarmRepeat(dayOfWeek, hour, minute, second, SoundAlarm); } else { Alarm.alarmRepeat(hour, minute, second, SoundAlarm); } } } std::vector<int> temp; temp.push_back(hour); temp.push_back(minute); temp.push_back(second); temp.push_back(isOnce); temp.push_back(light); temp.push_back(sound); temp.push_back(dayOfWeek); temp.push_back(false); vectorAlarmTimes.push_back(temp); updatePreferences(); updateAlarmString(); }
int mainForm::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = Q3MainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: fileOpen((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 1: fileOpen(); break; case 2: fileNew(); break; case 3: populateStructure(); break; case 4: populateTable((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 5: resetBrowser(); break; case 6: fileClose(); break; case 7: fileExit(); break; case 8: closeEvent((*reinterpret_cast< QCloseEvent*(*)>(_a[1]))); break; case 9: addRecord(); break; case 10: deleteRecord(); break; case 11: updateTableView((*reinterpret_cast< int(*)>(_a[1]))); break; case 12: selectTableLine((*reinterpret_cast< int(*)>(_a[1]))); break; case 13: navigatePrevious(); break; case 14: navigateNext(); break; case 15: navigateGoto(); break; case 16: setRecordsetLabel(); break; case 17: browseFind((*reinterpret_cast< bool(*)>(_a[1]))); break; case 18: browseFindAway(); break; case 19: lookfor((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break; case 20: showrecord((*reinterpret_cast< int(*)>(_a[1]))); break; case 21: createTable(); break; case 22: createIndex(); break; case 23: compact(); break; case 24: deleteTable(); break; case 25: editTable(); break; case 26: deleteIndex(); break; case 27: copy(); break; case 28: paste(); break; case 29: helpWhatsThis(); break; case 30: helpAbout(); break; case 31: updateRecordText((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])),(*reinterpret_cast< QString(*)>(_a[3]))); break; case 32: logWinAway(); break; case 33: editWinAway(); break; case 34: editText((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 35: doubleClickTable((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])),(*reinterpret_cast< int(*)>(_a[3])),(*reinterpret_cast< const QPoint(*)>(_a[4]))); break; case 36: executeQuery(); break; case 37: mainTabSelected((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 38: toggleLogWindow((*reinterpret_cast< bool(*)>(_a[1]))); break; case 39: importTableFromCSV(); break; case 40: exportTableToCSV(); break; case 41: dbState((*reinterpret_cast< bool(*)>(_a[1]))); break; case 42: fileSave(); break; case 43: fileRevert(); break; case 44: exportDatabaseToSQL(); break; case 45: importDatabaseFromSQL(); break; case 46: openPreferences(); break; case 47: updatePreferences(); break; case 48: languageChange(); break; default: ; } _id -= 49; } return _id; }