Skip to content

Commit

Permalink
Automatically sets the program windows' resolutions to match the curr…
Browse files Browse the repository at this point in the history
…ent desktop resolution.
  • Loading branch information
myzhan24 committed Sep 29, 2015
1 parent b2df3c5 commit 3431f7c
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 70 deletions.
5 changes: 0 additions & 5 deletions app/main.cpp
Expand Up @@ -25,12 +25,7 @@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);



MainWindow w;
w.show();


return a.exec();
}
108 changes: 62 additions & 46 deletions app/mainwindow.cpp
Expand Up @@ -29,14 +29,16 @@
#include "scformview.h"
#include <QTime>
#include <QMessageBox>
#include <QDesktopWidget>
#include "scitem.h"
//#include "scgraphicsview.h"
//#include "customgraphicsscene.h"

#define POP_UP_X 160
#define POP_UP_Y 200

#define SCALE_STEP 0.161803398875
//#define SCALE_STEP 0.161803398875
#define SCALE_STEP 0.15
#define SCALE_MIN 0.1
#define SCALE_MAX 3

Expand Down Expand Up @@ -86,49 +88,18 @@ MainWindow::MainWindow(QWidget *parent) :
#endif
this->setWindowTitle("Visual Statechart Editor");

this->resize(1272,1000);
this->move(633,0);


// add font widgets
createFontBar();

// uncomment this macro to autoload a file
// WARNING: outdated, may not work
//#define AUTO_LOAD_FILE

#ifdef AUTO_LOAD_FILE

#define DEFAULT_FILE "C:/visualsc/xmlfiles/statesequencemachine.scxml"
QString fileName =DEFAULT_FILE;
_settings->setValue(_keyLastFilePath, fileName);
/*
_project = new SMProject( ui->centralWidget );
connect (_project, SIGNAL(readInputFileCompleted(bool,QStringList)), this, SLOT(handleReadInputFileDone(bool,QStringList)) );
_project->readInputFile(fileName);
*/

// create the project
_project = new SMProject( ui->centralWidget );
connect( this, SIGNAL(reset()), _project->getDM(), SLOT(handleReset()));
// _project->initNewSM(); moved to constructor
ui->gridLayout->addWidget( _project->getQGraphicsView() );
_formEditorWindow = new SCFormView(0, _project->getDM());
_formEditorWindow->show();


// open the file
_project->getDM()->openFile(fileName);

// reselect the new root machine tree widget in the tree view
_formEditorWindow->highlightRootItem();

#endif

#ifndef AUTO_LOAD_FILE
_project = new SMProject( ui->centralWidget );
ui->gridLayout->addWidget( _project->getQGraphicsView() );
_formEditorWindow = new SCFormView(0, _project->getDM());

// main window actions
connect(_formEditorWindow, SIGNAL(newClick()), this, SLOT(handleNewClick()));
connect(_formEditorWindow, SIGNAL(openClick()), this, SLOT(handleFileOpenClick()));
connect(_formEditorWindow, SIGNAL(saveImageClick()), this, SLOT(on_actionSaveImage_triggered()));
Expand All @@ -140,7 +111,9 @@ MainWindow::MainWindow(QWidget *parent) :
_formEditorWindow->show();


#endif




// connects for the mainwindow to other modules

Expand All @@ -152,7 +125,6 @@ MainWindow::MainWindow(QWidget *parent) :
connect(this, SIGNAL(reset()), _project->getDM(), SLOT(handleReset()));

// no special protocol needed for formview. regular item deletion and creation is good enough
// connect(this, SIGNAL(reset()), _formEditorWindow, SLOT(handleReset()));
connect(this, SIGNAL(open(QString)), _project->getDM(), SLOT(handleOpen(QString)));

// when the grid action is toggled, the graphics view's scene will change its background
Expand All @@ -165,23 +137,48 @@ MainWindow::MainWindow(QWidget *parent) :
connect(_fontBox, SIGNAL(activated(QString)), this, SLOT(handleChangeFont(QString)));
connect(_fontSizeBox, SIGNAL(activated(QString)), this, SLOT(handleChangeFont(QString)));

// when a datamodel item is clicked, change the font box to match its attributes

// when the data model signals set program font, set the program font
// connect(_project->getDM(), SIGNAL(setProgramFont(QFont*)), this, SLOT(handleSetProgramFont(QFont*)));
connect(_project->getDM(), SIGNAL(setProgramFontFamily(FontFamilyAttribute*)), this, SLOT(handleSetProgramFontFamily(FontFamilyAttribute*)));

connect(_project->getDM(),SIGNAL(setProgramFontSize(FontSizeAttribute*)), this, SLOT(handleSetProgramFontSize(FontSizeAttribute*)));

connect(_project->getDM(), SIGNAL(setProgramFontBold(FontBoldAttribute*)), this, SLOT(handleSetProgramFontBold(FontBoldAttribute*)));

// when the data model emits a clicked signal, change the radio button selection
connect(_project->getDM(), SIGNAL(itemClicked()), this, SLOT(handleItemClicked()));

// load settings from settings.ini if it exists, otherwise create a settings.ini file
_settingsFileName = QDir::currentPath()+"/"+"settings.ini";
qDebug () << "settings file " << _settingsFileName;
// qDebug () << "settings file " << _settingsFileName;
loadSettings();


// resize the window
// based on the current resolution, set the formview and graphicsview sizes
// the height will be the same between the two
// the width of the formview will take up 1/3 of the screen
// the width of the graphicsview will take up 2/3 of the screen

#define W7_BORDER 7.5 // each of the windows 7 window borders are 7.5 pixels.

QRect desktop = QApplication::desktop()->availableGeometry();
qreal sysW = desktop.width();
qreal sysH = desktop.height();

sysW -= 2*(W7_BORDER); // account for window border
qreal gW = sysW*2/3;
qreal fW = sysW*1/3;
fW -= W7_BORDER; // space between windows
gW -= W7_BORDER;
qreal gH = sysH - 37.5; // 30 pixels + 7.5 pixels


qDebug() << "fw: " <<fW << " gw: "<< gW <<" gH: "<<gH;

this->resize(gW,gH);
this->move( fW + W7_BORDER+ W7_BORDER,0);




}

MainWindow::~MainWindow()
Expand Down Expand Up @@ -515,6 +512,9 @@ void MainWindow::saveSettings()
/**
* @brief MainWindow::loadSettings
* load settings from settings.ini
* if no settings are found, create a settings.ini file
*
* .exe must have write privilege
*/
void MainWindow::loadSettings()
{
Expand Down Expand Up @@ -565,6 +565,10 @@ void MainWindow::createSettings()
qDebug() << "creating settings in " << _settingsFileName;
}

/**
* @brief MainWindow::delay
* deprecated function
*/
void MainWindow::delay()
{
QTime dieTime= QTime::currentTime().addSecs(1);
Expand All @@ -576,9 +580,16 @@ void MainWindow::delay()
qDebug()<<"delay num states: " <<states.size();
}

/**
* @brief MainWindow::handleNewClick
*
* SLOT
*
* when a new project is clicked, reset the program
*/
void MainWindow::handleNewClick()
{
// alert the graphics view and form view to reset
// alert the data model, graphics view, and form view to reset
emit reset();

// reset the current save and export files.
Expand Down Expand Up @@ -755,7 +766,7 @@ void MainWindow::on_actionImport_triggered()

if(!current)
{
sendMessage("!","Please select a state to import into");
sendMessage("!","Please select the state to be imported into");
return;
}

Expand Down Expand Up @@ -875,8 +886,13 @@ void MainWindow::scale(qreal step)
qreal mult = (_scale+step)/(_scale);
_project->getQGraphicsView()->scale(mult, mult);
_scale *= mult;
qDebug() << "setting scale to : " << _scale;
emit scaleChanged(_scale); // alert the graphicsView that the scale changed

QString output = QString::number(_scale*100) +"%";
this->setWindowTitle(output);
// qDebug() << "setting scale to : " << _scale;
// emit scaleChanged(_scale); // alert the graphicsView that the scale changed


}

void MainWindow::on_actionSaveImage_triggered()
Expand Down
14 changes: 13 additions & 1 deletion app/mainwindow.ui
Expand Up @@ -2,14 +2,26 @@
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="windowModality">
<enum>Qt::NonModal</enum>
</property>
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1272</width>
<height>544</height>
<height>1000</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>1920</width>
<height>1200</height>
</size>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
Expand Down
3 changes: 1 addition & 2 deletions scdatamodel/cwstate.cpp
Expand Up @@ -61,14 +61,14 @@ void CWState::createSignalsAndSlots()
_entryRelaySlot = "Slot_StateEntry__" + _stateName+"()";
_exitRelaySlot = "Slot_StateExit__"+ _stateName+"()";

// get all things separated by n spaces "," then k spaces where n and k are 0, 1, 2, 3, ... spaces
QRegExp sep("\\s*,\\s*");

// add all entry actions
QString entryAction = _myState->getStringAttr("entryAction")->asString();
if(!entryAction.isEmpty())
{
// delete any spaces, otherwise there will be an error
// entryAction.replace("\s+,\s+",",");
QStringList entries = entryAction.split(sep);
for(int i = 0; i < entries.size(); i++)
{
Expand All @@ -86,7 +86,6 @@ void CWState::createSignalsAndSlots()
if(!exitAction.isEmpty())
{
// delete any spaces, otherwise an assertion error is thrown
// exitAction.replace(", ",",");
QStringList exits = exitAction.split(sep);
for(int i = 0; i < exits.size(); i++)
{
Expand Down
28 changes: 26 additions & 2 deletions scformview/scformview.cpp
Expand Up @@ -45,13 +45,14 @@
#include <QApplication>
#include <QHeaderView>
#include <QFileDialog>
#include <QDesktopWidget>


#define PROPERTY_TABLE_WIDTH_1 108 // smallest value while still having clearance for the longest attribute name connectToFinished
#define PROPERTY_TABLE_WIDTH_2 170

#define WINDOW_WIDTH 618
#define WINDOW_HEIGHT 1000
#define WINDOW_HEIGHT 1002


//#define TREEVIEW_COLOR_ENABLE
Expand All @@ -72,7 +73,9 @@ SCFormView::SCFormView(QWidget *parent, SCDataModel *dataModel) :
_currentlySelected(NULL)//,
//_previouslySelected(NULL)
{
this->resize(WINDOW_WIDTH, WINDOW_HEIGHT);



createActions();
createMenus();
createToolbars();
Expand Down Expand Up @@ -169,6 +172,27 @@ this->resize(WINDOW_WIDTH, WINDOW_HEIGHT);


initTree();


// resize the window
// based on the current resolution, set the formview and graphicsview sizes
// the height will be the same between the two
// the width of the formview will take up 1/3 of the screen
// the width of the graphicsview will take up 2/3 of the screen

#define W7_BORDER 7.5 // each of the windows 7 window borders are 7.5 pixels.

QRect desktop = QApplication::desktop()->availableGeometry();
qreal sysW = desktop.width();
qreal sysH = desktop.height();

sysW -= 2*(W7_BORDER); // account for window border
qreal fW = sysW*1/3;
fW -= W7_BORDER; // space between windows
qreal gH = sysH - 37.5; // 30 pixels + 7.5 pixels


this->resize(fW,gH);
}


Expand Down
18 changes: 9 additions & 9 deletions xmlfiles/statemachine.cpp
Expand Up @@ -30,14 +30,14 @@ StateMachine::StateMachine(QObject* parent):
_stateMachine(new QStateMachine(this)),
_stateMachine_1(new QState()),
_stateMachine_2(new QState()),
_leadingTrailing(new QState())
_lkasefJlsaefJalsefJasdlfjae4fIafEjStateMachine(new QState())

{
//////// State Machine: _stateMachine ////////
_stateMachine->addState(_stateMachine_1);
_stateMachine->addState(_stateMachine_2);
_stateMachine->addState(_leadingTrailing);
_stateMachine->setInitialState(_leadingTrailing);
_stateMachine->addState(_lkasefJlsaefJalsefJasdlfjae4fIafEjStateMachine);
_stateMachine->setInitialState(_lkasefJlsaefJalsefJasdlfjae4fIafEjStateMachine);

// Add transitions for the QStates using the transitions' private relay signals

Expand All @@ -47,16 +47,16 @@ StateMachine::StateMachine(QObject* parent):
connect(_stateMachine_1, SIGNAL(exited()), this, SIGNAL(Signal_StateExit___stateMachine_1()));
connect(_stateMachine_2, SIGNAL(entered()), this, SIGNAL(Signal_StateEntry___stateMachine_2()));
connect(_stateMachine_2, SIGNAL(exited()), this, SIGNAL(Signal_StateExit___stateMachine_2()));
connect(_leadingTrailing, SIGNAL(entered()), this, SIGNAL(Signal_StateEntry___leadingTrailing()));
connect(_leadingTrailing, SIGNAL(exited()), this, SIGNAL(Signal_StateExit___leadingTrailing()));
connect(_lkasefJlsaefJalsefJasdlfjae4fIafEjStateMachine, SIGNAL(entered()), this, SIGNAL(Signal_StateEntry___lkasefJlsaefJalsefJasdlfjae4fIafEjStateMachine()));
connect(_lkasefJlsaefJalsefJasdlfjae4fIafEjStateMachine, SIGNAL(exited()), this, SIGNAL(Signal_StateExit___lkasefJlsaefJalsefJasdlfjae4fIafEjStateMachine()));

// Connect the private QState signals to private slots for entry/exit handlers
connect(_stateMachine_1, SIGNAL(entered()), this, SLOT(Slot_StateEntry___stateMachine_1()));
connect(_stateMachine_1, SIGNAL(exited()), this, SLOT(Slot_StateExit___stateMachine_1()));
connect(_stateMachine_2, SIGNAL(entered()), this, SLOT(Slot_StateEntry___stateMachine_2()));
connect(_stateMachine_2, SIGNAL(exited()), this, SLOT(Slot_StateExit___stateMachine_2()));
connect(_leadingTrailing, SIGNAL(entered()), this, SLOT(Slot_StateEntry___leadingTrailing()));
connect(_leadingTrailing, SIGNAL(exited()), this, SLOT(Slot_StateExit___leadingTrailing()));
connect(_lkasefJlsaefJalsefJasdlfjae4fIafEjStateMachine, SIGNAL(entered()), this, SLOT(Slot_StateEntry___lkasefJlsaefJalsefJasdlfjae4fIafEjStateMachine()));
connect(_lkasefJlsaefJalsefJasdlfjae4fIafEjStateMachine, SIGNAL(exited()), this, SLOT(Slot_StateExit___lkasefJlsaefJalsefJasdlfjae4fIafEjStateMachine()));


}
Expand Down Expand Up @@ -99,15 +99,15 @@ void StateMachine::Slot_StateExit___stateMachine_2()

}

void StateMachine::Slot_StateEntry___leadingTrailing()
void StateMachine::Slot_StateEntry___lkasefJlsaefJalsefJasdlfjae4fIafEjStateMachine()
{
emit Action___wowDoCoolStuff();
emit Action___goodPeformance();
emit Action___and();
emit Action___handling();
}

void StateMachine::Slot_StateExit___leadingTrailing()
void StateMachine::Slot_StateExit___lkasefJlsaefJalsefJasdlfjae4fIafEjStateMachine()
{
emit Action___testingLeadingSpaces();
emit Action___testingTrailingSpaces();
Expand Down

0 comments on commit 3431f7c

Please sign in to comment.