MainWidget::MainWidget(QWidget *parent,const char *name) :QWidget(parent,name) { // // Read Command Options // RDCmdSwitch *cmd=new RDCmdSwitch(qApp->argc(),qApp->argv(),"rdgpimon","\n"); delete cmd; // // Set Window Size // setMinimumWidth(sizeHint().width()); setMaximumWidth(sizeHint().width()); setMinimumHeight(sizeHint().height()); setMaximumHeight(sizeHint().height()); // // Create Font // QFont font("helvetica",10,QFont::Normal); font.setPixelSize(10); setFont(font); QFont main_font("helvetica",12,QFont::Bold); main_font.setPixelSize(12); // // Create And Set Icon // gpi_rivendell_map=new QPixmap(rivendell_xpm); setIcon(*gpi_rivendell_map); // // Load Local Configs // gpi_config=new RDConfig(); gpi_config->load(); // // Open Database // gpi_db=QSqlDatabase::addDatabase(gpi_config->mysqlDriver()); if(!gpi_db) { QMessageBox::warning(this,tr("Database Error"), tr("Can't Connect","Unable to connect to mySQL Server!")); exit(0); } gpi_db->setDatabaseName(gpi_config->mysqlDbname()); gpi_db->setUserName(gpi_config->mysqlUsername()); gpi_db->setPassword(gpi_config->mysqlPassword()); gpi_db->setHostName(gpi_config->mysqlHostname()); if(!gpi_db->open()) { QMessageBox::warning(this,tr("Can't Connect"), tr("Unable to connect to mySQL Server!")); gpi_db->removeDatabase(gpi_config->mysqlDbname()); exit(0); } new RDDbHeartbeat(gpi_config->mysqlHeartbeatInterval(),this); // // RIPC Connection // gpi_ripc=new RDRipc(gpi_config->stationName()); gpi_ripc->setIgnoreMask(true); connect(gpi_ripc,SIGNAL(userChanged()),this,SLOT(userData())); connect(gpi_ripc,SIGNAL(gpiStateChanged(int,int,bool)), this,SLOT(gpiStateChangedData(int,int,bool))); connect(gpi_ripc,SIGNAL(gpoStateChanged(int,int,bool)), this,SLOT(gpoStateChangedData(int,int,bool))); connect(gpi_ripc,SIGNAL(gpiMaskChanged(int,int,bool)), this,SLOT(gpiMaskChangedData(int,int,bool))); connect(gpi_ripc,SIGNAL(gpoMaskChanged(int,int,bool)), this,SLOT(gpoMaskChangedData(int,int,bool))); connect(gpi_ripc,SIGNAL(gpiCartChanged(int,int,int,int)), this,SLOT(gpiCartChangedData(int,int,int,int))); connect(gpi_ripc,SIGNAL(gpoCartChanged(int,int,int,int)), this,SLOT(gpoCartChangedData(int,int,int,int))); gpi_ripc->connectHost("localhost",RIPCD_TCP_PORT,gpi_config->password()); // // RDStation // gpi_station=new RDStation(gpi_config->stationName()); // // RDMatrix; // gpi_matrix=NULL; // // Type Selector // gpi_type_box=new QComboBox(this,"gpi_type_box"); gpi_type_box->setGeometry(80,10,120,21); gpi_type_box->insertItem(tr("GPI (Inputs)")); gpi_type_box->insertItem(tr("GPO (Outputs)")); QLabel *label= new QLabel(gpi_type_box,tr("Show:"),this,"gpi_type_label"); label->setGeometry(20,10,55,21); label->setFont(main_font); label->setAlignment(AlignRight|AlignVCenter); connect(gpi_type_box,SIGNAL(activated(int)), this,SLOT(matrixActivatedData(int))); // // Matrix Selector // gpi_matrix_box=new QComboBox(this,"gpi_matrix_box"); gpi_matrix_box->setGeometry(280,10,80,21); for(int i=0;i<MAX_MATRICES;i++) { gpi_matrix_box->insertItem(QString().sprintf("%d",i)); } label=new QLabel(gpi_matrix_box,tr("Matrix:"),this,"gpi_matrix_label"); label->setGeometry(220,10,55,21); label->setFont(main_font); label->setAlignment(AlignRight|AlignVCenter); connect(gpi_matrix_box,SIGNAL(activated(int)), this,SLOT(matrixActivatedData(int))); // // GPI Indicators // for(int i=0;i<GPIMON_ROWS;i++) { for(int j=0;j<GPIMON_COLS;j++) { gpi_labels[i*GPIMON_COLS+j]=new GpiLabel(this); gpi_labels[i*GPIMON_COLS+j]->setGeometry(10+64*j,40+78*i, gpi_labels[i*GPIMON_COLS+j]-> sizeHint().width(), gpi_labels[i*GPIMON_COLS+j]-> sizeHint().height()); } } // // Up Button // gpi_up_button= new RDTransportButton(RDTransportButton::Up,this,"gpi_up_button"); gpi_up_button->setGeometry(10,sizeHint().height()-60,80,50); connect(gpi_up_button,SIGNAL(clicked()),this,SLOT(upData())); // // Down Button // gpi_down_button= new RDTransportButton(RDTransportButton::Down,this,"gpi_down_button"); gpi_down_button->setGeometry(100,sizeHint().height()-60,80,50); connect(gpi_down_button,SIGNAL(clicked()),this,SLOT(downData())); // // Color Key // label=new QLabel(tr("Green = ON Cart"),this); label->setGeometry(200,sizeHint().height()-50,300,12); label->setFont(main_font); label->setAlignment(AlignLeft|AlignVCenter); QPalette p=palette(); p.setColor(QPalette::Active,QColorGroup::Foreground,darkGreen); p.setColor(QPalette::Inactive,QColorGroup::Foreground,darkGreen); p.setColor(QPalette::Disabled,QColorGroup::Foreground,darkGreen); label->setPalette(p); label=new QLabel(tr("Red = OFF Cart"),this); label->setGeometry(200,sizeHint().height()-32,300,12); label->setFont(main_font); label->setAlignment(AlignLeft|AlignVCenter); p.setColor(QPalette::Active,QColorGroup::Foreground,darkRed); p.setColor(QPalette::Inactive,QColorGroup::Foreground,darkRed); p.setColor(QPalette::Disabled,QColorGroup::Foreground,darkRed); label->setPalette(p); // // Close Button // gpi_close_button=new QPushButton(this,"gpi_close_button"); gpi_close_button->setGeometry(sizeHint().width()-90,sizeHint().height()-60, 80,50); gpi_close_button->setFont(main_font); gpi_close_button->setText(tr("&Close")); connect(gpi_close_button,SIGNAL(clicked()),this,SLOT(quitMainWidget())); // // Start Up Timer // QTimer *timer=new QTimer(this,"start_up_timer"); connect(timer,SIGNAL(timeout()),this,SLOT(startUpData())); timer->start(GPIMON_START_UP_DELAY,true); }
MainWidget::MainWidget(QWidget *parent) :QWidget(parent) { new RDApplication(RDApplication::Gui,"rdgpimon","RDGPIMON_USAGE"); gpi_scroll_mode=false; // // Set Window Size // setMinimumWidth(sizeHint().width()); setMaximumWidth(sizeHint().width()); setMinimumHeight(sizeHint().height()); setMaximumHeight(sizeHint().height()); // // Create Fonts // QFont font("helvetica",10,QFont::Normal); font.setPixelSize(10); setFont(font); QFont list_font("helvetica",12,QFont::Normal); list_font.setPixelSize(12); QFont main_font("helvetica",12,QFont::Bold); main_font.setPixelSize(12); QFont title_font("helvetica",14,QFont::Bold); title_font.setPixelSize(14); // // Create And Set Icon // gpi_rivendell_map=new QPixmap(rivendell_xpm); setIcon(*gpi_rivendell_map); // // RIPC Connection // rda->ripc()->setIgnoreMask(true); connect(rda->ripc(),SIGNAL(userChanged()),this,SLOT(userData())); connect(rda->ripc(),SIGNAL(gpiStateChanged(int,int,bool)), this,SLOT(gpiStateChangedData(int,int,bool))); connect(rda->ripc(),SIGNAL(gpoStateChanged(int,int,bool)), this,SLOT(gpoStateChangedData(int,int,bool))); connect(rda->ripc(),SIGNAL(gpiMaskChanged(int,int,bool)), this,SLOT(gpiMaskChangedData(int,int,bool))); connect(rda->ripc(),SIGNAL(gpoMaskChanged(int,int,bool)), this,SLOT(gpoMaskChangedData(int,int,bool))); connect(rda->ripc(),SIGNAL(gpiCartChanged(int,int,int,int)), this,SLOT(gpiCartChangedData(int,int,int,int))); connect(rda->ripc(),SIGNAL(gpoCartChanged(int,int,int,int)), this,SLOT(gpoCartChangedData(int,int,int,int))); rda->ripc()->connectHost("localhost",RIPCD_TCP_PORT,rda->config()->password()); // // RDMatrix; // gpi_matrix=NULL; // // Type Selector // gpi_type_box=new QComboBox(this); gpi_type_box->setGeometry(80,10,120,21); gpi_type_box->insertItem(tr("GPI (Inputs)")); gpi_type_box->insertItem(tr("GPO (Outputs)")); QLabel *label=new QLabel(gpi_type_box,tr("Show:"),this); label->setGeometry(20,10,55,21); label->setFont(main_font); label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); connect(gpi_type_box,SIGNAL(activated(int)), this,SLOT(matrixActivatedData(int))); // // Matrix Selector // gpi_matrix_box=new QComboBox(this); gpi_matrix_box->setGeometry(280,10,80,21); for(int i=0;i<MAX_MATRICES;i++) { gpi_matrix_box->insertItem(QString().sprintf("%d",i)); } label=new QLabel(gpi_matrix_box,tr("Matrix:"),this); label->setGeometry(220,10,55,21); label->setFont(main_font); label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); connect(gpi_matrix_box,SIGNAL(activated(int)), this,SLOT(matrixActivatedData(int))); // // GPI Indicators // for(int i=0;i<GPIMON_ROWS;i++) { for(int j=0;j<GPIMON_COLS;j++) { gpi_labels[i*GPIMON_COLS+j]=new GpiLabel(this); gpi_labels[i*GPIMON_COLS+j]->setGeometry(10+64*j,40+78*i, gpi_labels[i*GPIMON_COLS+j]-> sizeHint().width(), gpi_labels[i*GPIMON_COLS+j]-> sizeHint().height()); } } // // Up Button // gpi_up_button= new RDTransportButton(RDTransportButton::Up,this); gpi_up_button->setGeometry(10,360,80,50); connect(gpi_up_button,SIGNAL(clicked()),this,SLOT(upData())); // // Down Button // gpi_down_button= new RDTransportButton(RDTransportButton::Down,this); gpi_down_button->setGeometry(100,360,80,50); connect(gpi_down_button,SIGNAL(clicked()),this,SLOT(downData())); // // Color Key // label=new QLabel(tr("Green = ON Cart"),this); label->setGeometry(200,370,300,12); label->setFont(main_font); label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); QPalette p=palette(); p.setColor(QPalette::Active,QColorGroup::Foreground,Qt::darkGreen); p.setColor(QPalette::Inactive,QColorGroup::Foreground,Qt::darkGreen); p.setColor(QPalette::Disabled,QColorGroup::Foreground,Qt::darkGreen); label->setPalette(p); label=new QLabel(tr("Red = OFF Cart"),this); label->setGeometry(200,392,300,12); label->setFont(main_font); label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); p.setColor(QPalette::Active,QColorGroup::Foreground,Qt::darkRed); p.setColor(QPalette::Inactive,QColorGroup::Foreground,Qt::darkRed); p.setColor(QPalette::Disabled,QColorGroup::Foreground,Qt::darkRed); label->setPalette(p); // // Events Log // label=new QLabel(tr("Events Log"),this); label->setFont(title_font); label->setAlignment(Qt::AlignCenter); label->setGeometry(110,423,sizeHint().width()-220,30); gpi_events_date_edit=new Q3DateEdit(this); gpi_events_date_edit->setGeometry(155,453,90,20); gpi_events_date_edit->setDate(QDate::currentDate()); connect(gpi_events_date_edit,SIGNAL(valueChanged(const QDate &)), this,SLOT(eventsDateChangedData(const QDate &))); gpi_events_date_label=new QLabel(gpi_events_date_edit,tr("Date")+":",this); gpi_events_date_label->setGeometry(100,453,50,20); gpi_events_date_label->setFont(main_font); gpi_events_date_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); gpi_events_state_box=new QComboBox(this); gpi_events_state_box->setGeometry(280,453,55,20); gpi_events_state_box->insertItem(tr("On")); gpi_events_state_box->insertItem(tr("Off")); gpi_events_state_box->insertItem(tr("Both")); connect(gpi_events_state_box,SIGNAL(activated(int)), this,SLOT(eventsStateChangedData(int))); gpi_events_state_label=new QLabel(gpi_events_state_box,tr("State")+":",this); gpi_events_state_label->setGeometry(225,453,50,20); gpi_events_state_label->setFont(main_font); gpi_events_state_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); gpi_events_list=new RDListView(this); gpi_events_list->setFont(main_font); gpi_events_list->setGeometry(110,480,sizeHint().width()-220,230); gpi_events_list->setItemMargin(5); gpi_events_list->setSelectionMode(Q3ListView::NoSelection); gpi_events_list->addColumn("Time"); gpi_events_list->setColumnAlignment(0,Qt::AlignHCenter); gpi_events_list->setColumnSortType(1,RDListView::TimeSort); gpi_events_list->addColumn(tr("Line")); gpi_events_list->setColumnAlignment(1,Qt::AlignHCenter); gpi_events_list->setColumnSortType(1,RDListView::GpioSort); gpi_events_list->addColumn(tr("State")); gpi_events_list->setColumnAlignment(2,Qt::AlignHCenter); gpi_events_scroll_button=new QPushButton(tr("Scroll"),this); gpi_events_scroll_button->setGeometry(sizeHint().width()-100,510,80,50); gpi_events_scroll_button->setFont(main_font); connect(gpi_events_scroll_button,SIGNAL(clicked()), this,SLOT(eventsScrollData())); gpi_scroll_color=palette(); gpi_scroll_color.setColor(QPalette::Active,QColorGroup::ButtonText, Qt::white); gpi_scroll_color.setColor(QPalette::Active,QColorGroup::Button, Qt::blue); gpi_scroll_color.setColor(QPalette::Active,QColorGroup::Background, Qt::lightGray); gpi_scroll_color.setColor(QPalette::Inactive,QColorGroup::ButtonText, Qt::white); gpi_scroll_color.setColor(QPalette::Inactive,QColorGroup::Button, Qt::blue); gpi_scroll_color.setColor(QPalette::Inactive,QColorGroup::Background, Qt::lightGray); gpi_events_report_button=new QPushButton(tr("Report"),this); gpi_events_report_button->setGeometry(sizeHint().width()-100,570,80,50); gpi_events_report_button->setFont(main_font); connect(gpi_events_report_button,SIGNAL(clicked()), this,SLOT(eventsReportData())); // // Start Up Timer // gpi_events_startup_timer=new QTimer(this); connect(gpi_events_startup_timer,SIGNAL(timeout()),this,SLOT(startUpData())); gpi_events_startup_timer->start(GPIMON_START_UP_DELAY,true); }