Changeset aecdf994f9 in tspsg for src
- Timestamp:
- Jun 22, 2009, 1:37:12 AM (15 years ago)
- Branches:
- 0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
- Children:
- d5384ee64e
- Parents:
- 799ba1e3f2
- Location:
- src
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main.cpp
r799ba1e3f2 raecdf994f9 30 30 { 31 31 QApplication app(argc, argv); 32 app.setOrganizationName("..::Lёppsville::.."); 33 app.setOrganizationDomain("www.leppsville.com"); 34 app.setApplicationName("TSPSG"); 32 35 /*/ i18n 33 36 // TODO: Make English as program's "native" language -
src/mainwindow.cpp
r799ba1e3f2 raecdf994f9 26 26 #include <QPrintDialog> 27 27 #endif // Q_OS_WINCE 28 #include "defines.h" 28 29 #include "mainwindow.h" 29 30 30 // TODO: Saving window state on close31 32 31 MainWindow::MainWindow(QWidget *parent) 33 : QMainWindow(parent) , randMin(1), randMax(10)32 : QMainWindow(parent) 34 33 { 35 34 setupUi(this); 35 QSettings settings(INI_FILE,QSettings::IniFormat); 36 spinCities->setValue(settings.value("NumCities",5).toInt()); 36 37 connect(actionSettingsSettings,SIGNAL(triggered()),this,SLOT(ChangeSettings())); 38 connect(actionHelpAbout,SIGNAL(triggered()),this,SLOT(showAbout())); 37 39 #ifndef Q_OS_WINCE 38 40 connect(actionFilePrintSetup,SIGNAL(triggered()),this,SLOT(PrintSetup())); … … 48 50 tabWidget->resize(rect.width(),rect.height() - toolBar->size().height()); 49 51 #else 50 // Centering MainWindow 51 // TODO: Loading of saved window state 52 rect.moveCenter(QApplication::desktop()->availableGeometry().center()); 52 if (settings.value("SavePos",false).toBool()) { 53 // Loading of saved window state 54 settings.beginGroup("MainWindow"); 55 resize(settings.value("Size",size()).toSize()); 56 move(settings.value("Position",pos()).toPoint()); 57 if (settings.value("Maximized",false).toBool()) 58 setWindowState(windowState() | Qt::WindowMaximized); 59 settings.endGroup(); 60 } else { 61 // Centering main window 62 rect.moveCenter(QApplication::desktop()->availableGeometry(this).center()); 63 setGeometry(rect); 64 } 53 65 #endif // Q_OS_WINCE 54 setGeometry(rect);55 66 qsrand(QDateTime().currentDateTime().toTime_t()); 56 67 tspmodel = new CTSPModel(); 57 tspmodel->randMin = randMin;58 tspmodel->randMax = randMax;59 68 tspmodel->setNumCities(spinCities->value()); 60 69 taskView->setModel(tspmodel); 70 #ifdef Q_OS_WINCE 71 taskView->resizeColumnsToContents(); 72 taskView->resizeRowsToContents(); 73 #endif // Q_OS_WINCE 61 74 } 62 75 63 76 void MainWindow::CitiesNumberChanged(int n) 64 77 { 78 #ifdef Q_OS_WINCE 79 int count = tspmodel->numCities(); 80 #endif // Q_OS_WINCE 65 81 tspmodel->setNumCities(n); 82 #ifdef Q_OS_WINCE 83 if (n > count) 84 for (int k = count; k < n; k++) { 85 taskView->resizeColumnToContents(k); 86 taskView->resizeRowToContents(k); 87 } 88 #endif // Q_OS_WINCE 66 89 } 67 90 … … 69 92 { 70 93 SettingsDialog sd(this); 71 sd.spinRandMin->setValue(randMin); 72 sd.spinRandMax->setValue(randMax); 73 if (sd.exec() == QDialog::Accepted) { 74 randMin = sd.spinRandMin->value(); 75 randMax = sd.spinRandMax->value(); 76 } 94 sd.exec(); 77 95 } 78 96 … … 88 106 { 89 107 tspmodel->randomize(); 108 #ifdef Q_OS_WINCE 109 taskView->resizeColumnsToContents(); 110 taskView->resizeRowsToContents(); 111 #endif // Q_OS_WINCE 90 112 } 91 113 … … 114 136 // tabWidget->setCurrentIndex(1); 115 137 } 138 139 void MainWindow::showAbout() 140 { 141 // TODO: Normal about window :-) 142 QString about = QString::fromUtf8("TSPSG - TSP Solver and Generator\n\ 143 Copyright (C) 2007-%1 Lёppa <contacts[at]oleksii[dot]name>\n\ 144 Qt library versions:\n\ 145 Compile time: %2\n\ 146 Runtime: %3\n\ 147 \n\ 148 TSPSG is licensed under the terms of the GNU General Public License. You should have received a copy of the GNU General Public License along with TSPSG.").arg(QDate().toString("%Y"),QT_VERSION_STR,qVersion()); 149 QMessageBox(QMessageBox::Information,"About",about).exec(); 150 } 151 152 #ifndef Q_OS_WINCE 153 void MainWindow::closeEvent(QCloseEvent *event) 154 { 155 // Saving windows state 156 QSettings settings(INI_FILE,QSettings::IniFormat); 157 settings.setValue("NumCities",spinCities->value()); 158 if (settings.value("SavePos",false).toBool()) { 159 settings.beginGroup("MainWindow"); 160 settings.setValue("Maximized",isMaximized()); 161 if (!isMaximized()) { 162 settings.setValue("Size",size()); 163 settings.setValue("Position",pos()); 164 } 165 settings.endGroup(); 166 } 167 QMainWindow::closeEvent(event); 168 } 169 #endif // Q_OS_WINCE -
src/mainwindow.h
r799ba1e3f2 raecdf994f9 40 40 public: 41 41 MainWindow(QWidget *parent = 0); 42 #ifndef Q_OS_WINCE 43 void closeEvent(QCloseEvent *event); 44 #endif // Q_OS_WINCE 42 45 private slots: 43 46 void ChangeSettings(); 47 void showAbout(); 44 48 #ifndef Q_OS_WINCE 45 49 void PrintSetup(); … … 50 54 private: 51 55 CTSPModel *tspmodel; 52 int randMin;53 int randMax;54 56 }; 55 57 -
src/settingsdialog.cpp
r799ba1e3f2 raecdf994f9 25 25 #include <QStatusTipEvent> 26 26 #include <QFontDialog> 27 #include <QColorDialog> 28 #include "defines.h" 27 29 #include "settingsdialog.h" 28 30 … … 35 37 connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int))); 36 38 connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked())); 39 connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked())); 37 40 // setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint); 38 41 setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint); … … 47 50 labelHint->setMinimumHeight(labelHint->height()); 48 51 #endif // Q_OS_WINCE 52 settings = new QSettings(INI_FILE,QSettings::IniFormat); 53 spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt()); 54 spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt()); 55 #ifndef Q_OS_WINCE 56 cbSaveState->setChecked(settings->value("SavePos",false).toBool()); 57 #endif // Q_OS_WINCE 58 settings->beginGroup("Print"); 59 font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>(); 60 color = settings->value("Color",DEF_FONT_COLOR).value<QColor>(); 61 #ifndef Q_OS_WINCE 62 spinLeftMargin->setValue(settings->value("Offset",DEF_OFFSET).toInt()); 63 #endif // Q_OS_WINCE 64 settings->endGroup(); 49 65 } 50 66 … … 69 85 void SettingsDialog::buttonFontClicked() 70 86 { 71 // TODO: Pass current font to dialog and save selected. 72 QFontDialog fd; 73 fd.exec(); 87 bool ok; 88 QFont font = QFontDialog::getFont(&ok,this->font,this); 89 if (ok) 90 this->font = font; 74 91 } 92 93 void SettingsDialog::buttonColorClicked() 94 { 95 QColorDialog cd(color,this); 96 if (cd.exec() == QDialog::Accepted) 97 color = cd.selectedColor(); 98 } 99 100 void SettingsDialog::accept() 101 { 102 #ifndef Q_OS_WINCE 103 settings->setValue("SavePos",cbSaveState->isChecked()); 104 #endif // Q_OS_WINCE 105 settings->setValue("MinCost",spinRandMin->value()); 106 settings->setValue("MaxCost",spinRandMax->value()); 107 settings->beginGroup("Print"); 108 settings->setValue("Font",font); 109 settings->setValue("Color",color); 110 #ifndef Q_OS_WINCE 111 settings->setValue("Offset",spinLeftMargin->value()); 112 #endif // Q_OS_WINCE 113 settings->endGroup(); 114 QDialog::accept(); 115 } -
src/settingsdialog.h
r799ba1e3f2 raecdf994f9 26 26 27 27 #include <QDialog> 28 #include <QSettings> 28 29 #ifdef Q_OS_WINCE 29 30 #include "ui_settingsdialog.ce.h" … … 39 40 40 41 private: 41 #ifndef WINCE 42 QSettings *settings; 43 QFont font; 44 QColor color; 45 #ifndef Q_OS_WINCE 42 46 bool event(QEvent *); 43 47 #endif 44 48 45 49 private slots: 50 void accept(); 46 51 void spinRandMinValueChanged(int val) { spinRandMax->setMinimum(val + 1); } 47 52 void buttonFontClicked(); 53 void buttonColorClicked(); 48 54 }; 49 55 -
src/tspmodel.cpp
r799ba1e3f2 raecdf994f9 23 23 24 24 #include <QtGui> 25 #include "defines.h" 25 26 #include "tspmodel.h" 26 27 27 28 CTSPModel::CTSPModel(QObject *parent) 28 : QAbstractTableModel(parent), randMin(1), randMax(10),nCities(0)29 : QAbstractTableModel(parent), nCities(0) 29 30 { 31 settings = new QSettings(INI_FILE,QSettings::IniFormat); 30 32 } 31 33 … … 115 117 void CTSPModel::setNumCities(int n) 116 118 { 119 int randMin = settings->value("MinCost",DEF_RAND_MIN).toInt(); 120 int randMax = settings->value("MaxCost",DEF_RAND_MAX).toInt(); 117 121 if (n == nCities) 118 122 return; … … 140 144 void CTSPModel::randomize() 141 145 { 146 int randMin = settings->value("MinCost",DEF_RAND_MIN).toInt(); 147 int randMax = settings->value("MaxCost",DEF_RAND_MAX).toInt(); 142 148 for (int r = 0; r < nCities; r++) 143 149 for (int c = 0; c < nCities; c++) -
src/tspmodel.h
r799ba1e3f2 raecdf994f9 31 31 #define MAX_CITIES 100 32 32 // This value means infinity :-) 33 #define INFINITY 1.7E+308 33 #ifndef INFINITY 34 #define INFINITY 1.7E+308 35 #endif 34 36 // This is string, which represents infinite value in table 35 37 #define INFSTR "---" 36 38 37 39 #include <QAbstractTableModel> 40 #include <QSettings> 38 41 39 42 class CTSPModel: public QAbstractTableModel … … 51 54 void setNumCities(int); 52 55 void randomize(); 53 int randMin;54 int randMax;55 56 private: 57 QSettings *settings; 56 58 double table[MAX_CITIES][MAX_CITIES]; 57 59 int nCities;
Note: See TracChangeset
for help on using the changeset viewer.