├── .gitignore ├── README.md ├── appendixC ├── jambifind │ └── FindDialog.java ├── jambigotocell │ ├── GoToCellDialog.java │ └── GoToCellDialog.jui ├── jambiplotter1 │ ├── JambiPlotter.java │ ├── jambiplotter.h │ ├── jambiplotter.pro │ └── jambiplotter.xml ├── jambiplotter2 │ ├── JambiPlotter.java │ ├── jambiplotter.h │ ├── jambiplotter.pro │ └── jambiplotter.xml └── plotter │ ├── images │ ├── zoomin.png │ └── zoomout.png │ ├── in1.txt │ ├── plotter.cpp │ ├── plotter.h │ ├── plotter.pro │ └── plotter.qrc ├── chap01 ├── age │ ├── age.cpp │ └── age.pro ├── hello │ ├── hello.cpp │ └── hello.pro └── quit │ ├── quit.cpp │ └── quit.pro ├── chap02 ├── find │ ├── find.pro │ ├── finddialog.cpp │ ├── finddialog.h │ └── main.cpp ├── gotocell1 │ ├── gotocell1.pro │ ├── gotocelldialog.ui │ └── main.cpp ├── gotocell2 │ ├── gotocell2.pro │ ├── gotocelldialog.cpp │ ├── gotocelldialog.h │ ├── gotocelldialog.ui │ └── main.cpp ├── gotocell3 │ ├── gotocell3.pro │ ├── gotocelldialog.cpp │ ├── gotocelldialog.h │ ├── gotocelldialog.ui │ └── main.cpp └── sort │ ├── main.cpp │ ├── sort.pro │ ├── sortdialog.cpp │ ├── sortdialog.h │ └── sortdialog.ui ├── chap03 └── spreadsheet │ ├── cell.cpp │ ├── cell.h │ ├── finddialog.cpp │ ├── finddialog.h │ ├── gotocelldialog.cpp │ ├── gotocelldialog.h │ ├── gotocelldialog.ui │ ├── images │ ├── copy.png │ ├── cut.png │ ├── find.png │ ├── gotocell.png │ ├── icon.png │ ├── new.png │ ├── open.png │ ├── paste.png │ └── save.png │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── sortdialog.cpp │ ├── sortdialog.h │ ├── sortdialog.ui │ ├── spreadsheet.cpp │ ├── spreadsheet.h │ ├── spreadsheet.pro │ └── spreadsheet.qrc ├── chap04 └── spreadsheet │ ├── cell.cpp │ ├── cell.h │ ├── finddialog.cpp │ ├── finddialog.h │ ├── gotocelldialog.cpp │ ├── gotocelldialog.h │ ├── gotocelldialog.ui │ ├── images │ ├── copy.png │ ├── cut.png │ ├── find.png │ ├── gotocell.png │ ├── icon.png │ ├── new.png │ ├── open.png │ ├── paste.png │ └── save.png │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── sortdialog.cpp │ ├── sortdialog.h │ ├── sortdialog.ui │ ├── spreadsheet.cpp │ ├── spreadsheet.h │ ├── spreadsheet.pro │ └── spreadsheet.qrc ├── chap05 ├── hexspinbox │ ├── hexspinbox.cpp │ ├── hexspinbox.h │ ├── hexspinbox.pro │ └── main.cpp ├── iconeditor │ ├── iconeditor.cpp │ ├── iconeditor.h │ ├── iconeditor.pro │ ├── iconeditor.qrc │ ├── images │ │ └── mouse.png │ └── main.cpp ├── iconeditorplugin │ ├── iconeditorplugin.cpp │ ├── iconeditorplugin.h │ ├── iconeditorplugin.pro │ ├── iconeditorplugin.qrc │ └── images │ │ └── iconeditor.png └── plotter │ ├── images │ ├── zoomin.png │ └── zoomout.png │ ├── in1.txt │ ├── main.cpp │ ├── plotter.cpp │ ├── plotter.h │ ├── plotter.pro │ └── plotter.qrc ├── chap06 ├── findfile1 │ ├── findfile1.pro │ ├── findfiledialog.cpp │ ├── findfiledialog.h │ └── main.cpp ├── findfile2 │ ├── findfile2.pro │ ├── findfiledialog.cpp │ ├── findfiledialog.h │ └── main.cpp ├── findfile3 │ ├── findfile3.pro │ ├── findfiledialog.cpp │ ├── findfiledialog.h │ └── main.cpp ├── mailclient │ ├── mailclient.cpp │ ├── mailclient.h │ ├── mailclient.pro │ └── main.cpp ├── mdieditor │ ├── editor.cpp │ ├── editor.h │ ├── images │ │ ├── copy.png │ │ ├── cut.png │ │ ├── document.png │ │ ├── icon.png │ │ ├── new.png │ │ ├── open.png │ │ ├── paste.png │ │ └── save.png │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── mdieditor.pro │ └── mdieditor.qrc ├── preferences │ ├── main.cpp │ ├── preferencedialog.cpp │ ├── preferencedialog.h │ └── preferences.pro └── splitter │ ├── splitter.cpp │ └── splitter.pro ├── chap07 └── ticker │ ├── main.cpp │ ├── ticker.cpp │ ├── ticker.h │ └── ticker.pro ├── chap08 ├── cityscape │ ├── annotation.cpp │ ├── annotation.h │ ├── cityblock.cpp │ ├── cityblock.h │ ├── cityscape.cpp │ ├── cityscape.h │ ├── cityscape.pro │ ├── cityview.cpp │ ├── cityview.h │ └── main.cpp ├── diagram │ ├── diagram.pro │ ├── diagramwindow.cpp │ ├── diagramwindow.h │ ├── images │ │ ├── bringtofront.png │ │ ├── colors.png │ │ ├── copy.png │ │ ├── cut.png │ │ ├── delete.png │ │ ├── link.png │ │ ├── node.png │ │ ├── paste.png │ │ └── sendtoback.png │ ├── link.cpp │ ├── link.h │ ├── main.cpp │ ├── node.cpp │ ├── node.h │ ├── propertiesdialog.cpp │ ├── propertiesdialog.h │ ├── propertiesdialog.ui │ └── resources.qrc └── oventimer │ ├── main.cpp │ ├── oventimer.cpp │ ├── oventimer.h │ └── oventimer.pro ├── chap09 └── projectchooser │ ├── images │ ├── leftarrow.png │ ├── person.png │ └── rightarrow.png │ ├── main.cpp │ ├── projectchooser.pro │ ├── projectchooser.qrc │ ├── projectdialog.cpp │ ├── projectdialog.h │ ├── projectdialog.ui │ ├── projectlistwidget.cpp │ └── projectlistwidget.h ├── chap10 ├── booleanparser │ ├── booleanmodel.cpp │ ├── booleanmodel.h │ ├── booleanparser.cpp │ ├── booleanparser.h │ ├── booleanparser.pro │ ├── booleanwindow.cpp │ ├── booleanwindow.h │ ├── main.cpp │ ├── node.cpp │ └── node.h ├── cities │ ├── cities.pro │ ├── citymodel.cpp │ ├── citymodel.h │ └── main.cpp ├── colornames │ ├── colornames.pro │ ├── colornamesdialog.cpp │ ├── colornamesdialog.h │ └── main.cpp ├── coordinatesetter │ ├── coordinatesetter.cpp │ ├── coordinatesetter.h │ ├── coordinatesetter.pro │ └── main.cpp ├── currencies │ ├── currencies.pro │ ├── currencymodel.cpp │ ├── currencymodel.h │ └── main.cpp ├── directoryviewer │ ├── directoryviewer.cpp │ ├── directoryviewer.h │ ├── directoryviewer.pro │ └── main.cpp ├── flowchartsymbolpicker │ ├── flowchartsymbolpicker.cpp │ ├── flowchartsymbolpicker.h │ ├── flowchartsymbolpicker.pro │ ├── flowchartsymbolpicker.qrc │ ├── images │ │ ├── data.png │ │ ├── decision.png │ │ ├── document.png │ │ ├── manual-input.png │ │ ├── manual-operation.png │ │ ├── on-page-reference.png │ │ ├── predefined-process.png │ │ ├── preparation.png │ │ ├── printer.png │ │ └── process.png │ └── main.cpp ├── settingsviewer │ ├── main.cpp │ ├── settingsviewer.cpp │ ├── settingsviewer.h │ └── settingsviewer.pro ├── teamleaders │ ├── main.cpp │ ├── teamleaders.pro │ ├── teamleadersdialog.cpp │ └── teamleadersdialog.h └── trackeditor │ ├── main.cpp │ ├── trackdelegate.cpp │ ├── trackdelegate.h │ ├── trackeditor.cpp │ ├── trackeditor.h │ └── trackeditor.pro ├── chap12 ├── imageconverter │ ├── convertdialog.cpp │ ├── convertdialog.h │ ├── convertdialog.ui │ ├── imageconverter.pro │ └── main.cpp ├── imagespace │ ├── imagespace.cpp │ └── imagespace.pro └── tidy │ ├── tidy.cpp │ └── tidy.pro ├── chap13 ├── scooters │ ├── main.cpp │ ├── scooters.pro │ ├── scooterwindow.cpp │ └── scooterwindow.h └── staffmanager │ ├── employeeform.cpp │ ├── employeeform.h │ ├── main.cpp │ ├── mainform.cpp │ ├── mainform.h │ └── staffmanager.pro ├── chap14 ├── imagepro │ ├── imagepro.pro │ ├── imagewindow.cpp │ ├── imagewindow.h │ ├── main.cpp │ ├── resizedialog.ui │ ├── transactionthread.cpp │ └── transactionthread.h ├── semaphores │ ├── semaphores.cpp │ └── semaphores.pro ├── threads │ ├── main.cpp │ ├── thread.cpp │ ├── thread.h │ ├── threaddialog.cpp │ ├── threaddialog.h │ └── threads.pro └── waitconditions │ ├── waitconditions.cpp │ └── waitconditions.pro ├── chap15 ├── ftpget │ ├── ftpget.cpp │ ├── ftpget.h │ ├── ftpget.pro │ └── main.cpp ├── httpget │ ├── httpget.cpp │ ├── httpget.h │ ├── httpget.pro │ └── main.cpp ├── spider │ ├── main.cpp │ ├── spider.cpp │ ├── spider.h │ └── spider.pro ├── tripplanner │ ├── main.cpp │ ├── tripplanner.cpp │ ├── tripplanner.h │ ├── tripplanner.pro │ └── tripplanner.ui ├── tripserver │ ├── clientsocket.cpp │ ├── clientsocket.h │ ├── main.cpp │ ├── tripserver.cpp │ ├── tripserver.h │ └── tripserver.pro ├── weatherballoon │ ├── main.cpp │ ├── weatherballoon.cpp │ ├── weatherballoon.h │ └── weatherballoon.pro └── weatherstation │ ├── main.cpp │ ├── weatherstation.cpp │ ├── weatherstation.h │ └── weatherstation.pro ├── chap16 ├── domparser │ ├── domparser.cpp │ ├── domparser.h │ ├── domparser.pro │ ├── in1.xml │ └── main.cpp ├── saxhandler │ ├── in1.xml │ ├── main.cpp │ ├── saxhandler.cpp │ ├── saxhandler.h │ └── saxhandler.pro ├── xmlstreamreader │ ├── in1.xml │ ├── main.cpp │ ├── xmlstreamreader.cpp │ ├── xmlstreamreader.h │ └── xmlstreamreader.pro └── xmlstreamwriter │ ├── xmlstreamwriter.cpp │ └── xmlstreamwriter.pro ├── chap19 ├── bronze │ ├── bronze.pro │ ├── bronze.qrc │ ├── bronzedialog.cpp │ ├── bronzedialog.h │ ├── bronzestyle.cpp │ ├── bronzestyle.h │ ├── images │ │ ├── background.png │ │ ├── checkmark-disabled.png │ │ ├── checkmark-partial.png │ │ └── checkmark.png │ └── main.cpp └── candy │ ├── candy.pro │ ├── candy.qrc │ ├── candydialog.cpp │ ├── candydialog.h │ ├── images │ ├── background.png │ ├── button-hover.png │ ├── button-pressed.png │ ├── button.png │ └── down-arrow.png │ ├── main.cpp │ └── qss │ └── candy.qss ├── chap20 ├── teapots │ ├── main.cpp │ ├── teapots.cpp │ ├── teapots.h │ └── teapots.pro ├── tetrahedron │ ├── main.cpp │ ├── tetrahedron.cpp │ ├── tetrahedron.h │ └── tetrahedron.pro └── vowelcube │ ├── main.cpp │ ├── vowelcube.cpp │ ├── vowelcube.h │ └── vowelcube.pro ├── chap21 ├── basiceffectsplugin │ ├── basiceffectsplugin.cpp │ ├── basiceffectsplugin.h │ └── basiceffectsplugin.pro ├── bronze │ ├── bronze.pro │ ├── bronze.qrc │ ├── bronzedialog.cpp │ ├── bronzedialog.h │ ├── bronzestyle.cpp │ ├── bronzestyle.h │ ├── images │ │ ├── background.png │ │ ├── checkmark-disabled.png │ │ ├── checkmark-partial.png │ │ └── checkmark.png │ └── main.cpp ├── bronzestyleplugin │ ├── bronzestyleplugin.cpp │ ├── bronzestyleplugin.h │ ├── bronzestyleplugin.pro │ └── images │ │ ├── background.png │ │ ├── checkmark-disabled.png │ │ ├── checkmark-partial.png │ │ └── checkmark.png ├── cursorplugin │ ├── cursorhandler.cpp │ ├── cursorhandler.h │ ├── cursorplugin.cpp │ ├── cursorplugin.h │ ├── cursorplugin.pro │ └── cursors │ │ ├── cross.cur │ │ ├── move.cur │ │ └── whatsthis.cur ├── extraeffectsplugin │ ├── extraeffectsplugin.cpp │ ├── extraeffectsplugin.h │ └── extraeffectsplugin.pro └── textart │ ├── main.cpp │ ├── textart.pro │ ├── textartdialog.cpp │ ├── textartdialog.h │ └── textartinterface.h ├── chap22 ├── calculator │ ├── calculator.cpp │ ├── calculator.h │ ├── calculator.pro │ ├── main.cpp │ └── scripts │ │ ├── cube.js │ │ ├── factorial.js │ │ └── pi.js ├── gaspump │ ├── data │ │ ├── 2008q2.gpx │ │ ├── 2008q2.p20 │ │ ├── 2008q3.gpx │ │ └── 2008q3.p20 │ ├── filterdialog.cpp │ ├── filterdialog.h │ ├── filterdialog.ui │ ├── gaspump.pro │ ├── main.cpp │ ├── pumpspreadsheet.cpp │ ├── pumpspreadsheet.h │ ├── pumpwindow.cpp │ ├── pumpwindow.h │ ├── scripting.cpp │ ├── scripting.h │ └── scripts │ │ ├── onlyok.js │ │ ├── p20togpx.js │ │ ├── tohtml.js │ │ └── toliters.js └── htmleditor │ ├── htmleditor.pro │ ├── htmlsyntaxhighlighter.cpp │ ├── htmlsyntaxhighlighter.h │ ├── htmlwindow.cpp │ ├── htmlwindow.h │ ├── main.cpp │ └── scripts │ ├── reformatdialog.js │ ├── reformatdialog.ui │ ├── statisticsdialog.js │ └── statisticsdialog.ui ├── chap23 ├── addressbook │ ├── abitem.cpp │ ├── abitem.h │ ├── addressbook.cpp │ ├── addressbook.h │ ├── addressbook.pro │ ├── editdialog.cpp │ ├── editdialog.h │ ├── editdialog.ui │ ├── main.cpp │ ├── qaxserver.rc │ └── vb │ │ ├── AddressBook.vbp │ │ ├── AddressBook.vbw │ │ ├── AddressList.frm │ │ └── EditDialog.frm ├── bouncer │ ├── axbouncer.cpp │ ├── axbouncer.h │ ├── bouncer.pro │ ├── demo.html │ ├── main.cpp │ ├── objectsafetyimpl.cpp │ ├── objectsafetyimpl.h │ ├── qaxserver.def │ └── qaxserver.rc ├── mediaplayer │ ├── main.cpp │ ├── mediaplayer.pro │ ├── playerwindow.cpp │ └── playerwindow.h └── tictactoe │ ├── application.cpp │ ├── application.h │ ├── main.cpp │ ├── tictactoe.cpp │ ├── tictactoe.h │ └── tictactoe.pro ├── chap24 ├── expenses │ ├── expense.cpp │ ├── expense.h │ ├── expensedialog.cpp │ ├── expensedialog.h │ ├── expenses.desktop │ ├── expenses.pro │ ├── expensewindow.cpp │ ├── expensewindow.h │ ├── main.cpp │ └── pics │ │ ├── add.png │ │ ├── cancel.png │ │ ├── clear.png │ │ ├── delete.png │ │ ├── edit.png │ │ ├── expenses.png │ │ ├── ok.png │ │ └── send.png └── unitconverter │ ├── main.cpp │ ├── pics │ └── Example.png │ ├── unitconverter.cpp │ ├── unitconverter.desktop │ ├── unitconverter.h │ └── unitconverter.pro └── examples.pro /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | 3 | *.slo 4 | *.lo 5 | *.o 6 | *.a 7 | *.la 8 | *.lai 9 | *.so 10 | *.dll 11 | *.dylib 12 | 13 | # Qt-es 14 | 15 | /.qmake.cache 16 | /.qmake.stash 17 | *.pro.user 18 | *.pro.user.* 19 | *.qbs.user 20 | *.qbs.user.* 21 | *.moc 22 | moc_*.cpp 23 | qrc_*.cpp 24 | ui_*.h 25 | Makefile* 26 | *build-* 27 | 28 | # QtCreator 29 | 30 | *.autosave 31 | 32 | # QtCtreator Qml 33 | *.qmlproject.user 34 | *.qmlproject.user.* 35 | 36 | # QtCtreator CMake 37 | CMakeLists.txt.user 38 | 39 | -------------------------------------------------------------------------------- /appendixC/jambigotocell/GoToCellDialog.java: -------------------------------------------------------------------------------- 1 | import com.trolltech.qt.core.*; 2 | import com.trolltech.qt.gui.*; 3 | 4 | public class GoToCellDialog extends QDialog { 5 | private Ui_GoToCellDialogClass ui = new Ui_GoToCellDialogClass(); 6 | 7 | public GoToCellDialog(QWidget parent) { 8 | super(parent); 9 | ui.setupUi(this); 10 | 11 | ui.okButton.setEnabled(false); 12 | 13 | QRegExp regExp = new QRegExp("[A-Za-z][1-9][0-9]{0,2}"); 14 | ui.lineEdit.setValidator(new QRegExpValidator(regExp, this)); 15 | 16 | ui.okButton.clicked.connect(this, "accept()"); 17 | ui.cancelButton.clicked.connect(this, "reject()"); 18 | } 19 | 20 | private void on_lineEdit_textChanged(String text) { 21 | ui.okButton.setEnabled(!text.isEmpty()); 22 | } 23 | 24 | public static void main(String[] args) { 25 | QApplication.initialize(args); 26 | GoToCellDialog testGoToCellDialog = new GoToCellDialog(null); 27 | testGoToCellDialog.show(); 28 | QApplication.exec(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /appendixC/jambiplotter1/JambiPlotter.java: -------------------------------------------------------------------------------- 1 | import java.lang.Math; 2 | import java.util.ArrayList; 3 | import com.trolltech.qt.core.*; 4 | import com.trolltech.qt.gui.*; 5 | import com.softwareinc.plotter.Plotter; 6 | import com.softwareinc.plotter.PlotSettings; 7 | 8 | public class JambiPlotter { 9 | public static void main(String[] args) { 10 | QApplication.initialize(args); 11 | 12 | PlotSettings settings = new PlotSettings(); 13 | settings.setMinX(0.0); 14 | settings.setMaxX(100.0); 15 | settings.setMinY(0.0); 16 | settings.setMaxY(100.0); 17 | 18 | int numPoints = 100; 19 | ArrayList points0 = new ArrayList(); 20 | ArrayList points1 = new ArrayList(); 21 | for (int x = 0; x < numPoints; ++x) { 22 | points0.add(new QPointF(x, Math.random() * 100)); 23 | points1.add(new QPointF(x, Math.random() * 100)); 24 | } 25 | 26 | Plotter plotter = new Plotter(); 27 | plotter.setWindowTitle(plotter.tr("Jambi Plotter")); 28 | plotter.setPlotSettings(settings); 29 | plotter.setCurveData(0, points0); 30 | plotter.setCurveData(1, points1); 31 | plotter.show(); 32 | 33 | QApplication.exec(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /appendixC/jambiplotter1/jambiplotter.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../plotter/plotter.h" 4 | -------------------------------------------------------------------------------- /appendixC/jambiplotter1/jambiplotter.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | TARGET = com_softwareinc_plotter 3 | DLLDESTDIR = . 4 | HEADERS = ../plotter/plotter.h 5 | SOURCES = ../plotter/plotter.cpp 6 | RESOURCES = ../plotter/plotter.qrc 7 | INCLUDEPATH += ../plotter \ 8 | $$(JAMBIPATH)/include \ 9 | $$(JAVA)/include 10 | unix { 11 | INCLUDEPATH += $$(JAVA)/include/linux 12 | } 13 | win32 { 14 | INCLUDEPATH += $$(JAVA)/include/win32 15 | } 16 | LIBS += -L$$(JAMBIPATH)/lib -lqtjambi 17 | 18 | include(../cpp/com_softwareinc_plotter/com_softwareinc_plotter.pri) 19 | -------------------------------------------------------------------------------- /appendixC/jambiplotter1/jambiplotter.xml: -------------------------------------------------------------------------------- 1 | 3 | 5 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /appendixC/jambiplotter2/JambiPlotter.java: -------------------------------------------------------------------------------- 1 | import java.lang.Math; 2 | import java.util.ArrayList; 3 | import com.trolltech.qt.core.*; 4 | import com.trolltech.qt.gui.*; 5 | import com.softwareinc.plotter2.Plotter; 6 | import com.softwareinc.plotter2.PlotSettings; 7 | 8 | public class JambiPlotter { 9 | public static void main(String[] args) { 10 | QApplication.initialize(args); 11 | 12 | PlotSettings settings = new PlotSettings(); 13 | settings.setMinX(0.0); 14 | settings.setMaxX(100.0); 15 | settings.setMinY(0.0); 16 | settings.setMaxY(100.0); 17 | 18 | int numPoints = 100; 19 | QPointF[] points0 = new QPointF[numPoints]; 20 | QPointF[] points1 = new QPointF[numPoints]; 21 | for (int x = 0; x < numPoints; ++x) { 22 | points0[x] = new QPointF(x, Math.random() * 100); 23 | points1[x] = new QPointF(x, Math.random() * 100); 24 | } 25 | 26 | Plotter plotter = new Plotter(); 27 | plotter.setWindowTitle(plotter.tr("Jambi Plotter")); 28 | plotter.setPlotSettings(settings); 29 | plotter.setCurveData(0, points0); 30 | plotter.setCurveData(1, points1); 31 | plotter.show(); 32 | 33 | QApplication.exec(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /appendixC/jambiplotter2/jambiplotter.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../plotter/plotter.h" 4 | -------------------------------------------------------------------------------- /appendixC/jambiplotter2/jambiplotter.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | TARGET = com_softwareinc_plotter2 3 | HEADERS = ../plotter/plotter.h 4 | SOURCES = ../plotter/plotter.cpp 5 | RESOURCES = ../plotter/plotter.qrc 6 | INCLUDEPATH += ../plotter \ 7 | $$(JAMBIPATH)/include \ 8 | $$(JAVA)/include 9 | unix { 10 | INCLUDEPATH += $$(JAVA)/include/linux 11 | } 12 | win32 { 13 | INCLUDEPATH += $$(JAVA)/include/win32 14 | } 15 | LIBS += -L$$(JAMBIPATH)/lib -lqtjambi 16 | 17 | include(../cpp/com_softwareinc_plotter2/com_softwareinc_plotter2.pri) 18 | -------------------------------------------------------------------------------- /appendixC/jambiplotter2/jambiplotter.xml: -------------------------------------------------------------------------------- 1 | 3 | 5 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | public final void setCurveData(int id, 15 | com.trolltech.qt.core.QPointF points[]) { 16 | setCurveData_private(id, java.util.Arrays.asList(points)); 17 | } 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /appendixC/plotter/images/zoomin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/appendixC/plotter/images/zoomin.png -------------------------------------------------------------------------------- /appendixC/plotter/images/zoomout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/appendixC/plotter/images/zoomout.png -------------------------------------------------------------------------------- /appendixC/plotter/plotter.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = plotter.h 3 | SOURCES = main.cpp \ 4 | plotter.cpp 5 | RESOURCES = plotter.qrc 6 | -------------------------------------------------------------------------------- /appendixC/plotter/plotter.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/zoomin.png 4 | images/zoomout.png 5 | in1.txt 6 | 7 | 8 | -------------------------------------------------------------------------------- /chap01/age/age.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | 10 | QWidget *window = new QWidget; 11 | window->setWindowTitle("Enter Your Age"); 12 | 13 | QSpinBox *spinBox = new QSpinBox; 14 | QSlider *slider = new QSlider(Qt::Horizontal); 15 | spinBox->setRange(0, 130); 16 | slider->setRange(0, 130); 17 | 18 | QObject::connect(spinBox, SIGNAL(valueChanged(int)), 19 | slider, SLOT(setValue(int))); 20 | QObject::connect(slider, SIGNAL(valueChanged(int)), 21 | spinBox, SLOT(setValue(int))); 22 | spinBox->setValue(35); 23 | 24 | QHBoxLayout *layout = new QHBoxLayout; 25 | layout->addWidget(spinBox); 26 | layout->addWidget(slider); 27 | window->setLayout(layout); 28 | 29 | window->show(); 30 | 31 | return app.exec(); 32 | } 33 | -------------------------------------------------------------------------------- /chap01/age/age.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | SOURCES = age.cpp 3 | -------------------------------------------------------------------------------- /chap01/hello/hello.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication app(argc, argv); 7 | QLabel *label = new QLabel("Hello Qt!"); 8 | label->show(); 9 | return app.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /chap01/hello/hello.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | SOURCES = hello.cpp 3 | -------------------------------------------------------------------------------- /chap01/quit/quit.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication app(argc, argv); 7 | QPushButton *button = new QPushButton("Quit"); 8 | QObject::connect(button, SIGNAL(clicked()), 9 | &app, SLOT(quit())); 10 | button->show(); 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /chap01/quit/quit.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | SOURCES = quit.cpp 3 | -------------------------------------------------------------------------------- /chap02/find/find.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = finddialog.h 3 | SOURCES = finddialog.cpp main.cpp 4 | 5 | QT += widgets 6 | -------------------------------------------------------------------------------- /chap02/find/finddialog.h: -------------------------------------------------------------------------------- 1 | #ifndef FINDDIALOG_H 2 | #define FINDDIALOG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class FindDialog : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | FindDialog(QWidget *parent = 0); 18 | 19 | signals: 20 | void findNext(const QString &str, Qt::CaseSensitivity cs); 21 | void findPrevious(const QString &str, Qt::CaseSensitivity cs); 22 | 23 | private slots: 24 | void findClicked(); 25 | void enableFindButton(const QString &text); 26 | 27 | private: 28 | QLabel *label; 29 | QLineEdit *lineEdit; 30 | QCheckBox *caseCheckBox; 31 | QCheckBox *backwardCheckBox; 32 | QPushButton *findButton; 33 | QPushButton *closeButton; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /chap02/find/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "finddialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | FindDialog *dialog = new FindDialog; 9 | dialog->show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap02/gotocell1/gotocell1.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | SOURCES = main.cpp 3 | FORMS = gotocelldialog.ui 4 | -------------------------------------------------------------------------------- /chap02/gotocell1/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "ui_gotocelldialog.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | 10 | Ui::GoToCellDialog ui; 11 | QDialog *dialog = new QDialog; 12 | ui.setupUi(dialog); 13 | dialog->show(); 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /chap02/gotocell2/gotocell2.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = gotocelldialog.h 3 | SOURCES = gotocelldialog.cpp \ 4 | main.cpp 5 | FORMS = gotocelldialog.ui 6 | -------------------------------------------------------------------------------- /chap02/gotocell2/gotocelldialog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "gotocelldialog.h" 4 | 5 | GoToCellDialog::GoToCellDialog(QWidget *parent) 6 | : QDialog(parent) 7 | { 8 | setupUi(this); 9 | 10 | QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}"); 11 | lineEdit->setValidator(new QRegExpValidator(regExp, this)); 12 | 13 | connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); 14 | connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); 15 | } 16 | 17 | void GoToCellDialog::on_lineEdit_textChanged() 18 | { 19 | okButton->setEnabled(lineEdit->hasAcceptableInput()); 20 | } 21 | -------------------------------------------------------------------------------- /chap02/gotocell2/gotocelldialog.h: -------------------------------------------------------------------------------- 1 | #ifndef GOTOCELLDIALOG_H 2 | #define GOTOCELLDIALOG_H 3 | 4 | #include 5 | 6 | #include "ui_gotocelldialog.h" 7 | 8 | class GoToCellDialog : public QDialog, public Ui::GoToCellDialog 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | GoToCellDialog(QWidget *parent = 0); 14 | 15 | private slots: 16 | void on_lineEdit_textChanged(); 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /chap02/gotocell2/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "gotocelldialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | GoToCellDialog *dialog = new GoToCellDialog; 9 | dialog->show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap02/gotocell3/gotocell3.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = gotocelldialog.h 3 | SOURCES = gotocelldialog.cpp \ 4 | main.cpp 5 | FORMS = gotocelldialog.ui 6 | -------------------------------------------------------------------------------- /chap02/gotocell3/gotocelldialog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "gotocelldialog.h" 4 | 5 | GoToCellDialog::GoToCellDialog(QWidget *parent) 6 | : QDialog(parent) 7 | { 8 | setupUi(this); 9 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); 10 | 11 | QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}"); 12 | lineEdit->setValidator(new QRegExpValidator(regExp, this)); 13 | 14 | connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); 15 | connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); 16 | } 17 | 18 | void GoToCellDialog::on_lineEdit_textChanged() 19 | { 20 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled( 21 | lineEdit->hasAcceptableInput()); 22 | } 23 | -------------------------------------------------------------------------------- /chap02/gotocell3/gotocelldialog.h: -------------------------------------------------------------------------------- 1 | #ifndef GOTOCELLDIALOG_H 2 | #define GOTOCELLDIALOG_H 3 | 4 | #include 5 | 6 | #include "ui_gotocelldialog.h" 7 | 8 | class GoToCellDialog : public QDialog, public Ui::GoToCellDialog 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | GoToCellDialog(QWidget *parent = 0); 14 | 15 | private slots: 16 | void on_lineEdit_textChanged(); 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /chap02/gotocell3/gotocelldialog.ui: -------------------------------------------------------------------------------- 1 | 2 | GoToCellDialog 3 | 4 | 5 | 6 | 0 7 | 0 8 | 273 9 | 83 10 | 11 | 12 | 13 | Go to Cell 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | &Cell Location: 22 | 23 | 24 | lineEdit 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | Qt::Horizontal 37 | 38 | 39 | QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok 40 | 41 | 42 | 43 | 44 | 45 | 46 | lineEdit 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /chap02/gotocell3/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "gotocelldialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | GoToCellDialog *dialog = new GoToCellDialog; 9 | dialog->show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap02/sort/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "sortdialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | SortDialog *dialog = new SortDialog; 9 | dialog->setColumnRange('C', 'F'); 10 | dialog->show(); 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /chap02/sort/sort.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = sortdialog.h 3 | SOURCES = main.cpp \ 4 | sortdialog.cpp 5 | FORMS = sortdialog.ui 6 | -------------------------------------------------------------------------------- /chap02/sort/sortdialog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "sortdialog.h" 4 | 5 | SortDialog::SortDialog(QWidget *parent) 6 | : QDialog(parent) 7 | { 8 | setupUi(this); 9 | 10 | secondaryGroupBox->hide(); 11 | tertiaryGroupBox->hide(); 12 | layout()->setSizeConstraint(QLayout::SetFixedSize); 13 | 14 | setColumnRange('A', 'Z'); 15 | } 16 | 17 | void SortDialog::setColumnRange(QChar first, QChar last) 18 | { 19 | primaryColumnCombo->clear(); 20 | secondaryColumnCombo->clear(); 21 | tertiaryColumnCombo->clear(); 22 | 23 | secondaryColumnCombo->addItem(tr("None")); 24 | tertiaryColumnCombo->addItem(tr("None")); 25 | 26 | primaryColumnCombo->setMinimumSize( 27 | secondaryColumnCombo->sizeHint()); 28 | 29 | QChar ch = first; 30 | while (ch <= last) { 31 | primaryColumnCombo->addItem(QString(ch)); 32 | secondaryColumnCombo->addItem(QString(ch)); 33 | tertiaryColumnCombo->addItem(QString(ch)); 34 | ch = ch.unicode() + 1; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /chap02/sort/sortdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef SORTDIALOG_H 2 | #define SORTDIALOG_H 3 | 4 | #include 5 | 6 | #include "ui_sortdialog.h" 7 | 8 | class SortDialog : public QDialog, public Ui::SortDialog 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | SortDialog(QWidget *parent = 0); 14 | 15 | void setColumnRange(QChar first, QChar last); 16 | }; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /chap03/spreadsheet/cell.h: -------------------------------------------------------------------------------- 1 | #ifndef CELL_H 2 | #define CELL_H 3 | 4 | #include 5 | 6 | class Cell : public QTableWidgetItem 7 | { 8 | public: 9 | Cell(); 10 | 11 | QTableWidgetItem *clone() const; 12 | void setData(int role, const QVariant &value); 13 | QVariant data(int role) const; 14 | void setFormula(const QString &formula); 15 | QString formula() const; 16 | void setDirty(); 17 | 18 | private: 19 | QVariant value() const; 20 | QVariant evalExpression(const QString &str, int &pos) const; 21 | QVariant evalTerm(const QString &str, int &pos) const; 22 | QVariant evalFactor(const QString &str, int &pos) const; 23 | 24 | mutable QVariant cachedValue; 25 | mutable bool cacheIsDirty; 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /chap03/spreadsheet/finddialog.h: -------------------------------------------------------------------------------- 1 | #ifndef FINDDIALOG_H 2 | #define FINDDIALOG_H 3 | 4 | #include 5 | 6 | class QCheckBox; 7 | class QLabel; 8 | class QLineEdit; 9 | class QPushButton; 10 | 11 | class FindDialog : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | FindDialog(QWidget *parent = 0); 17 | 18 | signals: 19 | void findNext(const QString &str, Qt::CaseSensitivity cs); 20 | void findPrevious(const QString &str, Qt::CaseSensitivity cs); 21 | 22 | private slots: 23 | void findClicked(); 24 | void enableFindButton(const QString &text); 25 | 26 | private: 27 | QLabel *label; 28 | QLineEdit *lineEdit; 29 | QCheckBox *caseCheckBox; 30 | QCheckBox *backwardCheckBox; 31 | QPushButton *findButton; 32 | QPushButton *closeButton; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /chap03/spreadsheet/gotocelldialog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "gotocelldialog.h" 4 | 5 | GoToCellDialog::GoToCellDialog(QWidget *parent) 6 | : QDialog(parent) 7 | { 8 | setupUi(this); 9 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); 10 | 11 | QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}"); 12 | lineEdit->setValidator(new QRegExpValidator(regExp, this)); 13 | 14 | connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); 15 | connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); 16 | } 17 | 18 | void GoToCellDialog::on_lineEdit_textChanged() 19 | { 20 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled( 21 | lineEdit->hasAcceptableInput()); 22 | } 23 | -------------------------------------------------------------------------------- /chap03/spreadsheet/gotocelldialog.h: -------------------------------------------------------------------------------- 1 | #ifndef GOTOCELLDIALOG_H 2 | #define GOTOCELLDIALOG_H 3 | 4 | #include 5 | 6 | #include "ui_gotocelldialog.h" 7 | 8 | class GoToCellDialog : public QDialog, public Ui::GoToCellDialog 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | GoToCellDialog(QWidget *parent = 0); 14 | 15 | private slots: 16 | void on_lineEdit_textChanged(); 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /chap03/spreadsheet/gotocelldialog.ui: -------------------------------------------------------------------------------- 1 | 2 | GoToCellDialog 3 | 4 | 5 | 6 | 0 7 | 0 8 | 273 9 | 83 10 | 11 | 12 | 13 | Go to Cell 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | &Cell Location: 22 | 23 | 24 | lineEdit 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | Qt::Horizontal 37 | 38 | 39 | QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok 40 | 41 | 42 | 43 | 44 | 45 | 46 | lineEdit 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /chap03/spreadsheet/images/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap03/spreadsheet/images/copy.png -------------------------------------------------------------------------------- /chap03/spreadsheet/images/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap03/spreadsheet/images/cut.png -------------------------------------------------------------------------------- /chap03/spreadsheet/images/find.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap03/spreadsheet/images/find.png -------------------------------------------------------------------------------- /chap03/spreadsheet/images/gotocell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap03/spreadsheet/images/gotocell.png -------------------------------------------------------------------------------- /chap03/spreadsheet/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap03/spreadsheet/images/icon.png -------------------------------------------------------------------------------- /chap03/spreadsheet/images/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap03/spreadsheet/images/new.png -------------------------------------------------------------------------------- /chap03/spreadsheet/images/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap03/spreadsheet/images/open.png -------------------------------------------------------------------------------- /chap03/spreadsheet/images/paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap03/spreadsheet/images/paste.png -------------------------------------------------------------------------------- /chap03/spreadsheet/images/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap03/spreadsheet/images/save.png -------------------------------------------------------------------------------- /chap03/spreadsheet/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "mainwindow.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | MainWindow mainWin; 9 | mainWin.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap03/spreadsheet/sortdialog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "sortdialog.h" 4 | 5 | SortDialog::SortDialog(QWidget *parent) 6 | : QDialog(parent) 7 | { 8 | setupUi(this); 9 | 10 | secondaryGroupBox->hide(); 11 | tertiaryGroupBox->hide(); 12 | layout()->setSizeConstraint(QLayout::SetFixedSize); 13 | 14 | setColumnRange('A', 'Z'); 15 | } 16 | 17 | void SortDialog::setColumnRange(QChar first, QChar last) 18 | { 19 | primaryColumnCombo->clear(); 20 | secondaryColumnCombo->clear(); 21 | tertiaryColumnCombo->clear(); 22 | 23 | secondaryColumnCombo->addItem(tr("None")); 24 | tertiaryColumnCombo->addItem(tr("None")); 25 | 26 | primaryColumnCombo->setMinimumSize( 27 | secondaryColumnCombo->sizeHint()); 28 | 29 | QChar ch = first; 30 | while (ch <= last) { 31 | primaryColumnCombo->addItem(QString(ch)); 32 | secondaryColumnCombo->addItem(QString(ch)); 33 | tertiaryColumnCombo->addItem(QString(ch)); 34 | ch = ch.unicode() + 1; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /chap03/spreadsheet/sortdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef SORTDIALOG_H 2 | #define SORTDIALOG_H 3 | 4 | #include 5 | 6 | #include "ui_sortdialog.h" 7 | 8 | class SortDialog : public QDialog, public Ui::SortDialog 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | SortDialog(QWidget *parent = 0); 14 | 15 | void setColumnRange(QChar first, QChar last); 16 | }; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /chap03/spreadsheet/spreadsheet.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = cell.h \ 3 | finddialog.h \ 4 | gotocelldialog.h \ 5 | mainwindow.h \ 6 | sortdialog.h \ 7 | spreadsheet.h 8 | SOURCES = cell.cpp \ 9 | finddialog.cpp \ 10 | gotocelldialog.cpp \ 11 | main.cpp \ 12 | mainwindow.cpp \ 13 | sortdialog.cpp \ 14 | spreadsheet.cpp 15 | FORMS = gotocelldialog.ui \ 16 | sortdialog.ui 17 | RESOURCES = spreadsheet.qrc 18 | -------------------------------------------------------------------------------- /chap03/spreadsheet/spreadsheet.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/icon.png 4 | images/new.png 5 | images/open.png 6 | images/save.png 7 | images/cut.png 8 | images/copy.png 9 | images/paste.png 10 | images/find.png 11 | images/gotocell.png 12 | 13 | 14 | -------------------------------------------------------------------------------- /chap04/spreadsheet/cell.h: -------------------------------------------------------------------------------- 1 | #ifndef CELL_H 2 | #define CELL_H 3 | 4 | #include 5 | 6 | class Cell : public QTableWidgetItem 7 | { 8 | public: 9 | Cell(); 10 | 11 | QTableWidgetItem *clone() const; 12 | void setData(int role, const QVariant &value); 13 | QVariant data(int role) const; 14 | void setFormula(const QString &formula); 15 | QString formula() const; 16 | void setDirty(); 17 | 18 | private: 19 | QVariant value() const; 20 | QVariant evalExpression(const QString &str, int &pos) const; 21 | QVariant evalTerm(const QString &str, int &pos) const; 22 | QVariant evalFactor(const QString &str, int &pos) const; 23 | 24 | mutable QVariant cachedValue; 25 | mutable bool cacheIsDirty; 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /chap04/spreadsheet/finddialog.h: -------------------------------------------------------------------------------- 1 | #ifndef FINDDIALOG_H 2 | #define FINDDIALOG_H 3 | 4 | #include 5 | 6 | class QCheckBox; 7 | class QLabel; 8 | class QLineEdit; 9 | class QPushButton; 10 | 11 | class FindDialog : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | FindDialog(QWidget *parent = 0); 17 | 18 | signals: 19 | void findNext(const QString &str, Qt::CaseSensitivity cs); 20 | void findPrevious(const QString &str, Qt::CaseSensitivity cs); 21 | 22 | private slots: 23 | void findClicked(); 24 | void enableFindButton(const QString &text); 25 | 26 | private: 27 | QLabel *label; 28 | QLineEdit *lineEdit; 29 | QCheckBox *caseCheckBox; 30 | QCheckBox *backwardCheckBox; 31 | QPushButton *findButton; 32 | QPushButton *closeButton; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /chap04/spreadsheet/gotocelldialog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "gotocelldialog.h" 4 | 5 | GoToCellDialog::GoToCellDialog(QWidget *parent) 6 | : QDialog(parent) 7 | { 8 | setupUi(this); 9 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); 10 | 11 | QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}"); 12 | lineEdit->setValidator(new QRegExpValidator(regExp, this)); 13 | 14 | connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); 15 | connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); 16 | } 17 | 18 | void GoToCellDialog::on_lineEdit_textChanged() 19 | { 20 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled( 21 | lineEdit->hasAcceptableInput()); 22 | } 23 | -------------------------------------------------------------------------------- /chap04/spreadsheet/gotocelldialog.h: -------------------------------------------------------------------------------- 1 | #ifndef GOTOCELLDIALOG_H 2 | #define GOTOCELLDIALOG_H 3 | 4 | #include 5 | 6 | #include "ui_gotocelldialog.h" 7 | 8 | class GoToCellDialog : public QDialog, public Ui::GoToCellDialog 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | GoToCellDialog(QWidget *parent = 0); 14 | 15 | private slots: 16 | void on_lineEdit_textChanged(); 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /chap04/spreadsheet/gotocelldialog.ui: -------------------------------------------------------------------------------- 1 | 2 | GoToCellDialog 3 | 4 | 5 | 6 | 0 7 | 0 8 | 273 9 | 83 10 | 11 | 12 | 13 | Go to Cell 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | &Cell Location: 22 | 23 | 24 | lineEdit 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | Qt::Horizontal 37 | 38 | 39 | QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok 40 | 41 | 42 | 43 | 44 | 45 | 46 | lineEdit 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /chap04/spreadsheet/images/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap04/spreadsheet/images/copy.png -------------------------------------------------------------------------------- /chap04/spreadsheet/images/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap04/spreadsheet/images/cut.png -------------------------------------------------------------------------------- /chap04/spreadsheet/images/find.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap04/spreadsheet/images/find.png -------------------------------------------------------------------------------- /chap04/spreadsheet/images/gotocell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap04/spreadsheet/images/gotocell.png -------------------------------------------------------------------------------- /chap04/spreadsheet/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap04/spreadsheet/images/icon.png -------------------------------------------------------------------------------- /chap04/spreadsheet/images/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap04/spreadsheet/images/new.png -------------------------------------------------------------------------------- /chap04/spreadsheet/images/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap04/spreadsheet/images/open.png -------------------------------------------------------------------------------- /chap04/spreadsheet/images/paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap04/spreadsheet/images/paste.png -------------------------------------------------------------------------------- /chap04/spreadsheet/images/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap04/spreadsheet/images/save.png -------------------------------------------------------------------------------- /chap04/spreadsheet/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "mainwindow.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | MainWindow mainWin; 9 | mainWin.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap04/spreadsheet/sortdialog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "sortdialog.h" 4 | 5 | SortDialog::SortDialog(QWidget *parent) 6 | : QDialog(parent) 7 | { 8 | setupUi(this); 9 | 10 | secondaryGroupBox->hide(); 11 | tertiaryGroupBox->hide(); 12 | layout()->setSizeConstraint(QLayout::SetFixedSize); 13 | 14 | setColumnRange('A', 'Z'); 15 | } 16 | 17 | void SortDialog::setColumnRange(QChar first, QChar last) 18 | { 19 | primaryColumnCombo->clear(); 20 | secondaryColumnCombo->clear(); 21 | tertiaryColumnCombo->clear(); 22 | 23 | secondaryColumnCombo->addItem(tr("None")); 24 | tertiaryColumnCombo->addItem(tr("None")); 25 | 26 | primaryColumnCombo->setMinimumSize( 27 | secondaryColumnCombo->sizeHint()); 28 | 29 | QChar ch = first; 30 | while (ch <= last) { 31 | primaryColumnCombo->addItem(QString(ch)); 32 | secondaryColumnCombo->addItem(QString(ch)); 33 | tertiaryColumnCombo->addItem(QString(ch)); 34 | ch = ch.unicode() + 1; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /chap04/spreadsheet/sortdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef SORTDIALOG_H 2 | #define SORTDIALOG_H 3 | 4 | #include 5 | 6 | #include "ui_sortdialog.h" 7 | 8 | class SortDialog : public QDialog, public Ui::SortDialog 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | SortDialog(QWidget *parent = 0); 14 | 15 | void setColumnRange(QChar first, QChar last); 16 | }; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /chap04/spreadsheet/spreadsheet.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = cell.h \ 3 | finddialog.h \ 4 | gotocelldialog.h \ 5 | mainwindow.h \ 6 | sortdialog.h \ 7 | spreadsheet.h 8 | SOURCES = cell.cpp \ 9 | finddialog.cpp \ 10 | gotocelldialog.cpp \ 11 | main.cpp \ 12 | mainwindow.cpp \ 13 | sortdialog.cpp \ 14 | spreadsheet.cpp 15 | FORMS = gotocelldialog.ui \ 16 | sortdialog.ui 17 | RESOURCES = spreadsheet.qrc 18 | -------------------------------------------------------------------------------- /chap04/spreadsheet/spreadsheet.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/icon.png 4 | images/new.png 5 | images/open.png 6 | images/save.png 7 | images/cut.png 8 | images/copy.png 9 | images/paste.png 10 | images/find.png 11 | images/gotocell.png 12 | 13 | 14 | -------------------------------------------------------------------------------- /chap05/hexspinbox/hexspinbox.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "hexspinbox.h" 4 | 5 | HexSpinBox::HexSpinBox(QWidget *parent) 6 | : QSpinBox(parent) 7 | { 8 | setRange(0, 255); 9 | validator = new QRegExpValidator(QRegExp("[0-9A-Fa-f]{1,8}"), this); 10 | } 11 | 12 | QValidator::State HexSpinBox::validate(QString &text, int &pos) const 13 | { 14 | return validator->validate(text, pos); 15 | } 16 | 17 | int HexSpinBox::valueFromText(const QString &text) const 18 | { 19 | bool ok; 20 | return text.toInt(&ok, 16); 21 | } 22 | 23 | QString HexSpinBox::textFromValue(int value) const 24 | { 25 | return QString::number(value, 16).toUpper(); 26 | } 27 | -------------------------------------------------------------------------------- /chap05/hexspinbox/hexspinbox.h: -------------------------------------------------------------------------------- 1 | #ifndef HEXSPINBOX_H 2 | #define HEXSPINBOX_H 3 | 4 | #include 5 | 6 | class QRegExpValidator; 7 | 8 | class HexSpinBox : public QSpinBox 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | HexSpinBox(QWidget *parent = 0); 14 | 15 | protected: 16 | QValidator::State validate(QString &text, int &pos) const; 17 | int valueFromText(const QString &text) const; 18 | QString textFromValue(int value) const; 19 | 20 | private: 21 | QRegExpValidator *validator; 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /chap05/hexspinbox/hexspinbox.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = hexspinbox.h 3 | SOURCES = hexspinbox.cpp \ 4 | main.cpp 5 | -------------------------------------------------------------------------------- /chap05/hexspinbox/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "hexspinbox.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | HexSpinBox spinBox; 10 | spinBox.setWindowTitle(QObject::tr("Hex Spin Box")); 11 | spinBox.show(); 12 | return app.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /chap05/iconeditor/iconeditor.h: -------------------------------------------------------------------------------- 1 | #ifndef ICONEDITOR_H 2 | #define ICONEDITOR_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class IconEditor : public QWidget 9 | { 10 | Q_OBJECT 11 | Q_PROPERTY(QColor penColor READ penColor WRITE setPenColor) 12 | Q_PROPERTY(QImage iconImage READ iconImage WRITE setIconImage) 13 | Q_PROPERTY(int zoomFactor READ zoomFactor WRITE setZoomFactor) 14 | 15 | public: 16 | IconEditor(QWidget *parent = 0); 17 | 18 | void setPenColor(const QColor &newColor); 19 | QColor penColor() const { return curColor; } 20 | void setZoomFactor(int newZoom); 21 | int zoomFactor() const { return zoom; } 22 | void setIconImage(const QImage &newImage); 23 | QImage iconImage() const { return image; } 24 | QSize sizeHint() const; 25 | 26 | protected: 27 | void mousePressEvent(QMouseEvent *event); 28 | void mouseMoveEvent(QMouseEvent *event); 29 | void paintEvent(QPaintEvent *event); 30 | 31 | private: 32 | void setImagePixel(const QPoint &pos, bool opaque); 33 | QRect pixelRect(int i, int j) const; 34 | 35 | QColor curColor; 36 | QImage image; 37 | int zoom; 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /chap05/iconeditor/iconeditor.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = iconeditor.h 3 | SOURCES = iconeditor.cpp \ 4 | main.cpp 5 | RESOURCES = iconeditor.qrc 6 | -------------------------------------------------------------------------------- /chap05/iconeditor/iconeditor.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/mouse.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /chap05/iconeditor/images/mouse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap05/iconeditor/images/mouse.png -------------------------------------------------------------------------------- /chap05/iconeditor/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "iconeditor.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | IconEditor iconEditor; 9 | iconEditor.setWindowTitle(QObject::tr("Icon Editor")); 10 | iconEditor.setIconImage(QImage(":/images/mouse.png")); 11 | iconEditor.show(); 12 | return app.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /chap05/iconeditorplugin/iconeditorplugin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../iconeditor/iconeditor.h" 4 | #include "iconeditorplugin.h" 5 | 6 | IconEditorPlugin::IconEditorPlugin(QObject *parent) 7 | : QObject(parent) 8 | { 9 | } 10 | 11 | QString IconEditorPlugin::name() const 12 | { 13 | return "IconEditor"; 14 | } 15 | 16 | QString IconEditorPlugin::includeFile() const 17 | { 18 | return "iconeditor.h"; 19 | } 20 | 21 | QString IconEditorPlugin::group() const 22 | { 23 | return tr("Image Manipulation Widgets"); 24 | } 25 | 26 | QIcon IconEditorPlugin::icon() const 27 | { 28 | return QIcon(":/images/iconeditor.png"); 29 | } 30 | 31 | QString IconEditorPlugin::toolTip() const 32 | { 33 | return tr("An icon editor widget"); 34 | } 35 | 36 | QString IconEditorPlugin::whatsThis() const 37 | { 38 | return tr("This widget is presented in Chapter 5 of C++ GUI " 39 | "Programming with Qt 4 as an example of a custom Qt " 40 | "widget."); 41 | } 42 | 43 | bool IconEditorPlugin::isContainer() const 44 | { 45 | return false; 46 | } 47 | 48 | QWidget *IconEditorPlugin::createWidget(QWidget *parent) 49 | { 50 | return new IconEditor(parent); 51 | } 52 | 53 | Q_EXPORT_PLUGIN2(iconeditorplugin, IconEditorPlugin) 54 | -------------------------------------------------------------------------------- /chap05/iconeditorplugin/iconeditorplugin.h: -------------------------------------------------------------------------------- 1 | #ifndef ICONEDITORPLUGIN_H 2 | #define ICONEDITORPLUGIN_H 3 | 4 | #include 5 | 6 | class IconEditorPlugin : public QObject, 7 | public QDesignerCustomWidgetInterface 8 | { 9 | Q_OBJECT 10 | Q_INTERFACES(QDesignerCustomWidgetInterface) 11 | 12 | public: 13 | IconEditorPlugin(QObject *parent = 0); 14 | 15 | QString name() const; 16 | QString includeFile() const; 17 | QString group() const; 18 | QIcon icon() const; 19 | QString toolTip() const; 20 | QString whatsThis() const; 21 | bool isContainer() const; 22 | QWidget *createWidget(QWidget *parent); 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /chap05/iconeditorplugin/iconeditorplugin.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | CONFIG += designer plugin release 3 | HEADERS = ../iconeditor/iconeditor.h \ 4 | iconeditorplugin.h 5 | SOURCES = ../iconeditor/iconeditor.cpp \ 6 | iconeditorplugin.cpp 7 | RESOURCES = iconeditorplugin.qrc 8 | DESTDIR = $$[QT_INSTALL_PLUGINS]/designer 9 | -------------------------------------------------------------------------------- /chap05/iconeditorplugin/iconeditorplugin.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/iconeditor.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /chap05/iconeditorplugin/images/iconeditor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap05/iconeditorplugin/images/iconeditor.png -------------------------------------------------------------------------------- /chap05/plotter/images/zoomin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap05/plotter/images/zoomin.png -------------------------------------------------------------------------------- /chap05/plotter/images/zoomout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap05/plotter/images/zoomout.png -------------------------------------------------------------------------------- /chap05/plotter/plotter.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = plotter.h 3 | SOURCES = main.cpp \ 4 | plotter.cpp 5 | RESOURCES = plotter.qrc 6 | -------------------------------------------------------------------------------- /chap05/plotter/plotter.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/zoomin.png 4 | images/zoomout.png 5 | in1.txt 6 | 7 | 8 | -------------------------------------------------------------------------------- /chap06/findfile1/findfile1.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = findfiledialog.h 3 | SOURCES = findfiledialog.cpp \ 4 | main.cpp 5 | -------------------------------------------------------------------------------- /chap06/findfile1/findfiledialog.h: -------------------------------------------------------------------------------- 1 | #ifndef FINDFILEDIALOG_H 2 | #define FINDFILEDIALOG_H 3 | 4 | #include 5 | 6 | class QCheckBox; 7 | class QLabel; 8 | class QLineEdit; 9 | class QPushButton; 10 | class QTableWidget; 11 | 12 | class FindFileDialog : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | FindFileDialog(QWidget *parent = 0); 18 | 19 | private: 20 | QLabel *namedLabel; 21 | QLabel *lookInLabel; 22 | QLineEdit *lookInLineEdit; 23 | QLineEdit *namedLineEdit; 24 | QCheckBox *subfoldersCheckBox; 25 | QTableWidget *tableWidget; 26 | QLabel *messageLabel; 27 | QPushButton *findButton; 28 | QPushButton *stopButton; 29 | QPushButton *closeButton; 30 | QPushButton *helpButton; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /chap06/findfile1/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "findfiledialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | FindFileDialog dialog; 9 | dialog.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap06/findfile2/findfile2.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = findfiledialog.h 3 | SOURCES = findfiledialog.cpp \ 4 | main.cpp 5 | -------------------------------------------------------------------------------- /chap06/findfile2/findfiledialog.h: -------------------------------------------------------------------------------- 1 | #ifndef FINDFILEDIALOG_H 2 | #define FINDFILEDIALOG_H 3 | 4 | #include 5 | 6 | class QCheckBox; 7 | class QLabel; 8 | class QLineEdit; 9 | class QPushButton; 10 | class QTableWidget; 11 | 12 | class FindFileDialog : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | FindFileDialog(QWidget *parent = 0); 18 | 19 | protected: 20 | void resizeEvent(QResizeEvent *event); 21 | 22 | private: 23 | QLabel *namedLabel; 24 | QLabel *lookInLabel; 25 | QLineEdit *lookInLineEdit; 26 | QLineEdit *namedLineEdit; 27 | QCheckBox *subfoldersCheckBox; 28 | QTableWidget *tableWidget; 29 | QLabel *messageLabel; 30 | QPushButton *findButton; 31 | QPushButton *stopButton; 32 | QPushButton *closeButton; 33 | QPushButton *helpButton; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /chap06/findfile2/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "findfiledialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | FindFileDialog dialog; 9 | dialog.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap06/findfile3/findfile3.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = findfiledialog.h 3 | SOURCES = findfiledialog.cpp \ 4 | main.cpp 5 | -------------------------------------------------------------------------------- /chap06/findfile3/findfiledialog.h: -------------------------------------------------------------------------------- 1 | #ifndef FINDFILEDIALOG_H 2 | #define FINDFILEDIALOG_H 3 | 4 | #include 5 | 6 | class QCheckBox; 7 | class QLabel; 8 | class QLineEdit; 9 | class QPushButton; 10 | class QTableWidget; 11 | 12 | class FindFileDialog : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | FindFileDialog(QWidget *parent = 0); 18 | 19 | private: 20 | QLabel *namedLabel; 21 | QLabel *lookInLabel; 22 | QLineEdit *lookInLineEdit; 23 | QLineEdit *namedLineEdit; 24 | QCheckBox *subfoldersCheckBox; 25 | QTableWidget *tableWidget; 26 | QLabel *messageLabel; 27 | QPushButton *findButton; 28 | QPushButton *stopButton; 29 | QPushButton *closeButton; 30 | QPushButton *helpButton; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /chap06/findfile3/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "findfiledialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | FindFileDialog dialog; 9 | dialog.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap06/mailclient/mailclient.h: -------------------------------------------------------------------------------- 1 | #ifndef MAILCLIENT_H 2 | #define MAILCLIENT_H 3 | 4 | #include 5 | 6 | class QIcon; 7 | class QSplitter; 8 | class QTextEdit; 9 | class QTreeWidget; 10 | 11 | class MailClient : public QMainWindow 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | MailClient(); 17 | 18 | protected: 19 | void closeEvent(QCloseEvent *event); 20 | 21 | private: 22 | void addFolder(const QIcon &icon, const QString &name); 23 | void addMessage(const QString &subject, const QString &from, 24 | const QString &date); 25 | void readSettings(); 26 | void writeSettings(); 27 | 28 | QSplitter *mainSplitter; 29 | QSplitter *rightSplitter; 30 | QTreeWidget *foldersTreeWidget; 31 | QTreeWidget *messagesTreeWidget; 32 | QTextEdit *textEdit; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /chap06/mailclient/mailclient.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = mailclient.h 3 | SOURCES = mailclient.cpp \ 4 | main.cpp 5 | -------------------------------------------------------------------------------- /chap06/mailclient/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "mailclient.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | MailClient client; 9 | client.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap06/mdieditor/editor.h: -------------------------------------------------------------------------------- 1 | #ifndef EDITOR_H 2 | #define EDITOR_H 3 | 4 | #include 5 | 6 | class Editor : public QTextEdit 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | Editor(QWidget *parent = 0); 12 | 13 | void newFile(); 14 | bool save(); 15 | bool saveAs(); 16 | QSize sizeHint() const; 17 | QAction *windowMenuAction() const { return action; } 18 | 19 | static Editor *open(QWidget *parent = 0); 20 | static Editor *openFile(const QString &fileName, 21 | QWidget *parent = 0); 22 | 23 | protected: 24 | void closeEvent(QCloseEvent *event); 25 | 26 | private slots: 27 | void documentWasModified(); 28 | 29 | private: 30 | bool okToContinue(); 31 | bool saveFile(const QString &fileName); 32 | void setCurrentFile(const QString &fileName); 33 | bool readFile(const QString &fileName); 34 | bool writeFile(const QString &fileName); 35 | QString strippedName(const QString &fullFileName); 36 | 37 | QString curFile; 38 | bool isUntitled; 39 | QAction *action; 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /chap06/mdieditor/images/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap06/mdieditor/images/copy.png -------------------------------------------------------------------------------- /chap06/mdieditor/images/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap06/mdieditor/images/cut.png -------------------------------------------------------------------------------- /chap06/mdieditor/images/document.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap06/mdieditor/images/document.png -------------------------------------------------------------------------------- /chap06/mdieditor/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap06/mdieditor/images/icon.png -------------------------------------------------------------------------------- /chap06/mdieditor/images/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap06/mdieditor/images/new.png -------------------------------------------------------------------------------- /chap06/mdieditor/images/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap06/mdieditor/images/open.png -------------------------------------------------------------------------------- /chap06/mdieditor/images/paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap06/mdieditor/images/paste.png -------------------------------------------------------------------------------- /chap06/mdieditor/images/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap06/mdieditor/images/save.png -------------------------------------------------------------------------------- /chap06/mdieditor/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "mainwindow.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | MainWindow mainWin; 9 | mainWin.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap06/mdieditor/mdieditor.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = editor.h \ 3 | mainwindow.h 4 | SOURCES = editor.cpp \ 5 | main.cpp \ 6 | mainwindow.cpp 7 | RESOURCES = mdieditor.qrc 8 | -------------------------------------------------------------------------------- /chap06/mdieditor/mdieditor.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/copy.png 4 | images/cut.png 5 | images/document.png 6 | images/icon.png 7 | images/new.png 8 | images/open.png 9 | images/paste.png 10 | images/save.png 11 | 12 | 13 | -------------------------------------------------------------------------------- /chap06/preferences/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "preferencedialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | PreferenceDialog dialog; 9 | dialog.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap06/preferences/preferences.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = preferencedialog.h 3 | SOURCES = main.cpp \ 4 | preferencedialog.cpp 5 | -------------------------------------------------------------------------------- /chap06/splitter/splitter.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | SOURCES = splitter.cpp 3 | -------------------------------------------------------------------------------- /chap07/ticker/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "ticker.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | Ticker ticker; 9 | ticker.setWindowTitle(QObject::tr("Ticker")); 10 | ticker.setText(QObject::tr("How long it lasted was impossible to " 11 | "say ++ ")); 12 | ticker.show(); 13 | return app.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /chap07/ticker/ticker.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "ticker.h" 4 | 5 | Ticker::Ticker(QWidget *parent) 6 | : QWidget(parent) 7 | { 8 | offset = 0; 9 | myTimerId = 0; 10 | } 11 | 12 | void Ticker::setText(const QString &newText) 13 | { 14 | myText = newText; 15 | update(); 16 | updateGeometry(); 17 | } 18 | 19 | QSize Ticker::sizeHint() const 20 | { 21 | return fontMetrics().size(0, text()); 22 | } 23 | 24 | void Ticker::paintEvent(QPaintEvent * /* event */) 25 | { 26 | QPainter painter(this); 27 | 28 | int textWidth = fontMetrics().width(text()); 29 | if (textWidth < 1) 30 | return; 31 | int x = -offset; 32 | while (x < width()) { 33 | painter.drawText(x, 0, textWidth, height(), 34 | Qt::AlignLeft | Qt::AlignVCenter, text()); 35 | x += textWidth; 36 | } 37 | } 38 | 39 | void Ticker::showEvent(QShowEvent * /* event */) 40 | { 41 | myTimerId = startTimer(30); 42 | } 43 | 44 | void Ticker::timerEvent(QTimerEvent *event) 45 | { 46 | if (event->timerId() == myTimerId) { 47 | ++offset; 48 | if (offset >= fontMetrics().width(text())) 49 | offset = 0; 50 | scroll(-1, 0); 51 | } else { 52 | QWidget::timerEvent(event); 53 | } 54 | } 55 | 56 | void Ticker::hideEvent(QHideEvent * /* event */) 57 | { 58 | killTimer(myTimerId); 59 | myTimerId = 0; 60 | } 61 | -------------------------------------------------------------------------------- /chap07/ticker/ticker.h: -------------------------------------------------------------------------------- 1 | #ifndef TICKER_H 2 | #define TICKER_H 3 | 4 | #include 5 | 6 | class Ticker : public QWidget 7 | { 8 | Q_OBJECT 9 | Q_PROPERTY(QString text READ text WRITE setText) 10 | 11 | public: 12 | Ticker(QWidget *parent = 0); 13 | 14 | void setText(const QString &newText); 15 | QString text() const { return myText; } 16 | QSize sizeHint() const; 17 | 18 | protected: 19 | void paintEvent(QPaintEvent *event); 20 | void timerEvent(QTimerEvent *event); 21 | void showEvent(QShowEvent *event); 22 | void hideEvent(QHideEvent *event); 23 | 24 | private: 25 | QString myText; 26 | int offset; 27 | int myTimerId; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /chap07/ticker/ticker.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = ticker.h 3 | SOURCES = main.cpp \ 4 | ticker.cpp 5 | -------------------------------------------------------------------------------- /chap08/cityscape/annotation.h: -------------------------------------------------------------------------------- 1 | #ifndef ANNOTATION_H 2 | #define ANNOTATION_H 3 | 4 | #include 5 | 6 | class Annotation : public QGraphicsItem 7 | { 8 | public: 9 | Annotation(const QString &text, bool major = false); 10 | 11 | void setText(const QString &text); 12 | QString text() const; 13 | 14 | QRectF boundingRect() const; 15 | void paint(QPainter *painter, 16 | const QStyleOptionGraphicsItem *option, QWidget *widget); 17 | 18 | private: 19 | QFont font; 20 | QString str; 21 | bool major; 22 | double threshold; 23 | int y; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /chap08/cityscape/cityblock.h: -------------------------------------------------------------------------------- 1 | #ifndef CITYBLOCK_H 2 | #define CITYBLOCK_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class QGradient; 9 | 10 | class CityBlock : public QGraphicsItem 11 | { 12 | public: 13 | enum Kind { Park, SmallBuilding, Hospital, Hall, Building, Tower, 14 | LShapedBlock, LShapedBlockPlusSmallBlock, TwoBlocks, 15 | BlockPlusTwoSmallBlocks }; 16 | 17 | CityBlock(Kind kind); 18 | 19 | QRectF boundingRect() const; 20 | void paint(QPainter *painter, 21 | const QStyleOptionGraphicsItem *option, QWidget *widget); 22 | 23 | private: 24 | int kind; 25 | QColor color; 26 | QPainterPath shape; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /chap08/cityscape/cityscape.h: -------------------------------------------------------------------------------- 1 | #ifndef CITYSCAPE_H 2 | #define CITYSCAPE_H 3 | 4 | #include 5 | 6 | class QGraphicsScene; 7 | class CityView; 8 | 9 | class Cityscape : public QMainWindow 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | Cityscape(); 15 | 16 | private: 17 | void generateCityBlocks(); 18 | 19 | QGraphicsScene *scene; 20 | CityView *view; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /chap08/cityscape/cityscape.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = annotation.h \ 3 | cityblock.h \ 4 | cityscape.h \ 5 | cityview.h 6 | SOURCES = annotation.cpp \ 7 | cityblock.cpp \ 8 | cityscape.cpp \ 9 | cityview.cpp \ 10 | main.cpp 11 | -------------------------------------------------------------------------------- /chap08/cityscape/cityview.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "cityview.h" 5 | 6 | CityView::CityView(QWidget *parent) 7 | : QGraphicsView(parent) 8 | { 9 | setDragMode(ScrollHandDrag); 10 | } 11 | 12 | void CityView::wheelEvent(QWheelEvent *event) 13 | { 14 | double numDegrees = -event->delta() / 8.0; 15 | double numSteps = numDegrees / 15.0; 16 | double factor = std::pow(1.125, numSteps); 17 | scale(factor, factor); 18 | } 19 | -------------------------------------------------------------------------------- /chap08/cityscape/cityview.h: -------------------------------------------------------------------------------- 1 | #ifndef CITYVIEW_H 2 | #define CITYVIEW_H 3 | 4 | #include 5 | 6 | class CityView : public QGraphicsView 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | CityView(QWidget *parent = 0); 12 | 13 | protected: 14 | void wheelEvent(QWheelEvent *event); 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /chap08/cityscape/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "cityscape.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | Cityscape cityscape; 9 | cityscape.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap08/diagram/diagram.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = diagramwindow.h \ 3 | link.h \ 4 | node.h \ 5 | propertiesdialog.h 6 | SOURCES = diagramwindow.cpp \ 7 | link.cpp \ 8 | main.cpp \ 9 | node.cpp \ 10 | propertiesdialog.cpp 11 | FORMS = propertiesdialog.ui 12 | RESOURCES = resources.qrc 13 | -------------------------------------------------------------------------------- /chap08/diagram/images/bringtofront.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap08/diagram/images/bringtofront.png -------------------------------------------------------------------------------- /chap08/diagram/images/colors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap08/diagram/images/colors.png -------------------------------------------------------------------------------- /chap08/diagram/images/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap08/diagram/images/copy.png -------------------------------------------------------------------------------- /chap08/diagram/images/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap08/diagram/images/cut.png -------------------------------------------------------------------------------- /chap08/diagram/images/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap08/diagram/images/delete.png -------------------------------------------------------------------------------- /chap08/diagram/images/link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap08/diagram/images/link.png -------------------------------------------------------------------------------- /chap08/diagram/images/node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap08/diagram/images/node.png -------------------------------------------------------------------------------- /chap08/diagram/images/paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap08/diagram/images/paste.png -------------------------------------------------------------------------------- /chap08/diagram/images/sendtoback.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap08/diagram/images/sendtoback.png -------------------------------------------------------------------------------- /chap08/diagram/link.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "link.h" 4 | #include "node.h" 5 | 6 | Link::Link(Node *fromNode, Node *toNode) 7 | { 8 | myFromNode = fromNode; 9 | myToNode = toNode; 10 | 11 | myFromNode->addLink(this); 12 | myToNode->addLink(this); 13 | 14 | setFlags(QGraphicsItem::ItemIsSelectable); 15 | setZValue(-1); 16 | 17 | setColor(Qt::darkRed); 18 | trackNodes(); 19 | } 20 | 21 | Link::~Link() 22 | { 23 | myFromNode->removeLink(this); 24 | myToNode->removeLink(this); 25 | } 26 | 27 | Node *Link::fromNode() const 28 | { 29 | return myFromNode; 30 | } 31 | 32 | Node *Link::toNode() const 33 | { 34 | return myToNode; 35 | } 36 | 37 | void Link::setColor(const QColor &color) 38 | { 39 | setPen(QPen(color, 1.0)); 40 | } 41 | 42 | QColor Link::color() const 43 | { 44 | return pen().color(); 45 | } 46 | 47 | void Link::trackNodes() 48 | { 49 | setLine(QLineF(myFromNode->pos(), myToNode->pos())); 50 | } 51 | -------------------------------------------------------------------------------- /chap08/diagram/link.h: -------------------------------------------------------------------------------- 1 | #ifndef LINK_H 2 | #define LINK_H 3 | 4 | #include 5 | 6 | class Node; 7 | 8 | class Link : public QGraphicsLineItem 9 | { 10 | public: 11 | Link(Node *fromNode, Node *toNode); 12 | ~Link(); 13 | 14 | Node *fromNode() const; 15 | Node *toNode() const; 16 | 17 | void setColor(const QColor &color); 18 | QColor color() const; 19 | 20 | void trackNodes(); 21 | 22 | private: 23 | Node *myFromNode; 24 | Node *myToNode; 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /chap08/diagram/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "diagramwindow.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | DiagramWindow view; 9 | view.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap08/diagram/node.h: -------------------------------------------------------------------------------- 1 | #ifndef NODE_H 2 | #define NODE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class Link; 10 | 11 | class Node : public QGraphicsItem 12 | { 13 | Q_DECLARE_TR_FUNCTIONS(Node) 14 | 15 | public: 16 | Node(); 17 | ~Node(); 18 | 19 | void setText(const QString &text); 20 | QString text() const; 21 | void setTextColor(const QColor &color); 22 | QColor textColor() const; 23 | void setOutlineColor(const QColor &color); 24 | QColor outlineColor() const; 25 | void setBackgroundColor(const QColor &color); 26 | QColor backgroundColor() const; 27 | 28 | void addLink(Link *link); 29 | void removeLink(Link *link); 30 | 31 | QRectF boundingRect() const; 32 | QPainterPath shape() const; 33 | void paint(QPainter *painter, 34 | const QStyleOptionGraphicsItem *option, QWidget *widget); 35 | 36 | protected: 37 | void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); 38 | QVariant itemChange(GraphicsItemChange change, 39 | const QVariant &value); 40 | 41 | private: 42 | QRectF outlineRect() const; 43 | int roundness(double size) const; 44 | 45 | QSet myLinks; 46 | QString myText; 47 | QColor myTextColor; 48 | QColor myBackgroundColor; 49 | QColor myOutlineColor; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /chap08/diagram/propertiesdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef PROPERTIESDIALOG_H 2 | #define PROPERTIESDIALOG_H 3 | 4 | #include "ui_propertiesdialog.h" 5 | 6 | class Node; 7 | 8 | class PropertiesDialog : public QDialog, private Ui::PropertiesDialog 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | PropertiesDialog(Node *node, QWidget *parent = 0); 14 | 15 | private slots: 16 | void on_buttonBox_accepted(); 17 | void on_textColorButton_clicked(); 18 | void on_outlineColorButton_clicked(); 19 | void on_backgroundColorButton_clicked(); 20 | 21 | private: 22 | void updateColorLabel(QLabel *label, const QColor &color); 23 | void chooseColor(QLabel *label, QColor *color); 24 | 25 | Node *node; 26 | QColor textColor; 27 | QColor outlineColor; 28 | QColor backgroundColor; 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /chap08/diagram/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/bringtofront.png 4 | images/colors.png 5 | images/copy.png 6 | images/cut.png 7 | images/delete.png 8 | images/link.png 9 | images/node.png 10 | images/paste.png 11 | images/sendtoback.png 12 | 13 | 14 | -------------------------------------------------------------------------------- /chap08/oventimer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "oventimer.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | OvenTimer ovenTimer; 9 | ovenTimer.setWindowTitle(QObject::tr("Oven Timer")); 10 | ovenTimer.resize(300, 300); 11 | ovenTimer.show(); 12 | return app.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /chap08/oventimer/oventimer.h: -------------------------------------------------------------------------------- 1 | #ifndef OVENTIMER_H 2 | #define OVENTIMER_H 3 | 4 | #include 5 | #include 6 | 7 | class QTimer; 8 | 9 | class OvenTimer : public QWidget 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | OvenTimer(QWidget *parent = 0); 15 | 16 | void setDuration(int secs); 17 | int duration() const; 18 | void draw(QPainter *painter); 19 | 20 | signals: 21 | void timeout(); 22 | 23 | protected: 24 | void paintEvent(QPaintEvent *event); 25 | void mousePressEvent(QMouseEvent *event); 26 | 27 | private: 28 | QDateTime finishTime; 29 | QTimer *updateTimer; 30 | QTimer *finishTimer; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /chap08/oventimer/oventimer.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += exceptions 3 | HEADERS = oventimer.h 4 | SOURCES = main.cpp \ 5 | oventimer.cpp 6 | -------------------------------------------------------------------------------- /chap09/projectchooser/images/leftarrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap09/projectchooser/images/leftarrow.png -------------------------------------------------------------------------------- /chap09/projectchooser/images/person.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap09/projectchooser/images/person.png -------------------------------------------------------------------------------- /chap09/projectchooser/images/rightarrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap09/projectchooser/images/rightarrow.png -------------------------------------------------------------------------------- /chap09/projectchooser/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "projectdialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | ProjectDialog dialog; 9 | dialog.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap09/projectchooser/projectchooser.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = projectdialog.h \ 3 | projectlistwidget.h 4 | SOURCES = main.cpp \ 5 | projectdialog.cpp \ 6 | projectlistwidget.cpp 7 | FORMS = projectdialog.ui 8 | RESOURCES = projectchooser.qrc 9 | -------------------------------------------------------------------------------- /chap09/projectchooser/projectchooser.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/leftarrow.png 4 | images/person.png 5 | images/rightarrow.png 6 | 7 | 8 | -------------------------------------------------------------------------------- /chap09/projectchooser/projectdialog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "projectdialog.h" 4 | 5 | ProjectDialog::ProjectDialog(QWidget *parent) 6 | : QDialog(parent) 7 | { 8 | setupUi(this); 9 | 10 | projectA->addItem("Giosue Carducci"); 11 | projectA->addItem("Eyvind Johnson"); 12 | projectA->addItem("Sally Prudhomme"); 13 | projectA->addItem("Henryk Sienkiewicz"); 14 | projectA->addItem("Carl Spitteler"); 15 | projectA->addItem("Rabindranath Tagore"); 16 | projectA->addItem("Kawabata Yasunari"); 17 | 18 | projectB->addItem("Rudolf Eucken"); 19 | projectB->addItem("Anatole France"); 20 | projectB->addItem("Rudyard Kipling"); 21 | projectB->addItem("Thomas Mann"); 22 | projectB->addItem("Eugene O'Neill"); 23 | projectB->addItem("Sigrid Undset"); 24 | } 25 | 26 | void ProjectDialog::on_leftButton_clicked() 27 | { 28 | moveCurrentItem(projectB, projectA); 29 | } 30 | 31 | void ProjectDialog::on_rightButton_clicked() 32 | { 33 | moveCurrentItem(projectA, projectB); 34 | } 35 | 36 | void ProjectDialog::moveCurrentItem(ProjectListWidget *source, 37 | ProjectListWidget *target) 38 | { 39 | if (source->currentItem()) { 40 | QListWidgetItem *newItem = source->currentItem()->clone(); 41 | target->addItem(newItem); 42 | target->setCurrentItem(newItem); 43 | delete source->currentItem(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /chap09/projectchooser/projectdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef PROJECTDIALOG_H 2 | #define PROJECTDIALOG_H 3 | 4 | #include 5 | 6 | #include "ui_projectdialog.h" 7 | 8 | class ProjectDialog : public QDialog, private Ui::ProjectDialog 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | ProjectDialog(QWidget *parent = 0); 14 | 15 | public slots: 16 | void on_leftButton_clicked(); 17 | void on_rightButton_clicked(); 18 | 19 | private: 20 | void moveCurrentItem(ProjectListWidget *source, 21 | ProjectListWidget *target); 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /chap09/projectchooser/projectlistwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef PROJECTLISTWIDGET_H 2 | #define PROJECTLISTWIDGET_H 3 | 4 | #include 5 | 6 | class ProjectListWidget : public QListWidget 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | ProjectListWidget(QWidget *parent = 0); 12 | 13 | protected: 14 | void mousePressEvent(QMouseEvent *event); 15 | void mouseMoveEvent(QMouseEvent *event); 16 | void dragEnterEvent(QDragEnterEvent *event); 17 | void dragMoveEvent(QDragMoveEvent *event); 18 | void dropEvent(QDropEvent *event); 19 | 20 | private: 21 | void performDrag(); 22 | 23 | QPoint startPos; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /chap10/booleanparser/booleanmodel.h: -------------------------------------------------------------------------------- 1 | #ifndef BOOLEANMODEL_H 2 | #define BOOLEANMODEL_H 3 | 4 | #include 5 | 6 | class Node; 7 | 8 | class BooleanModel : public QAbstractItemModel 9 | { 10 | public: 11 | BooleanModel(QObject *parent = 0); 12 | ~BooleanModel(); 13 | 14 | void setRootNode(Node *node); 15 | 16 | QModelIndex index(int row, int column, 17 | const QModelIndex &parent) const; 18 | QModelIndex parent(const QModelIndex &child) const; 19 | 20 | int rowCount(const QModelIndex &parent) const; 21 | int columnCount(const QModelIndex &parent) const; 22 | QVariant data(const QModelIndex &index, int role) const; 23 | QVariant headerData(int section, Qt::Orientation orientation, 24 | int role) const; 25 | 26 | private: 27 | Node *nodeFromIndex(const QModelIndex &index) const; 28 | 29 | Node *rootNode; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /chap10/booleanparser/booleanparser.h: -------------------------------------------------------------------------------- 1 | #ifndef BOOLEANPARSER_H 2 | #define BOOLEANPARSER_H 3 | 4 | #include "node.h" 5 | 6 | class BooleanParser 7 | { 8 | public: 9 | Node *parse(const QString &expr); 10 | 11 | private: 12 | Node *parseOrExpression(); 13 | Node *parseAndExpression(); 14 | Node *parseNotExpression(); 15 | Node *parseAtom(); 16 | Node *parseIdentifier(); 17 | void addChild(Node *parent, Node *child); 18 | void addToken(Node *parent, const QString &str, Node::Type type); 19 | bool matchToken(const QString &str) const; 20 | 21 | QString in; 22 | int pos; 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /chap10/booleanparser/booleanparser.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = booleanmodel.h \ 3 | booleanparser.h \ 4 | booleanwindow.h \ 5 | node.h 6 | SOURCES = booleanmodel.cpp \ 7 | booleanparser.cpp \ 8 | booleanwindow.cpp \ 9 | main.cpp \ 10 | node.cpp 11 | -------------------------------------------------------------------------------- /chap10/booleanparser/booleanwindow.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "booleanmodel.h" 4 | #include "booleanparser.h" 5 | #include "booleanwindow.h" 6 | 7 | BooleanWindow::BooleanWindow() 8 | { 9 | label = new QLabel(tr("Boolean expression:")); 10 | lineEdit = new QLineEdit; 11 | 12 | booleanModel = new BooleanModel(this); 13 | 14 | treeView = new QTreeView; 15 | treeView->setModel(booleanModel); 16 | 17 | connect(lineEdit, SIGNAL(textChanged(const QString &)), 18 | this, SLOT(booleanExpressionChanged(const QString &))); 19 | 20 | QGridLayout *layout = new QGridLayout; 21 | layout->addWidget(label, 0, 0); 22 | layout->addWidget(lineEdit, 0, 1); 23 | layout->addWidget(treeView, 1, 0, 1, 2); 24 | setLayout(layout); 25 | 26 | setWindowTitle(tr("Boolean Parser")); 27 | } 28 | 29 | void BooleanWindow::booleanExpressionChanged(const QString &expr) 30 | { 31 | BooleanParser parser; 32 | Node *rootNode = parser.parse(expr); 33 | booleanModel->setRootNode(rootNode); 34 | } 35 | -------------------------------------------------------------------------------- /chap10/booleanparser/booleanwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef BOOLEANWINDOW_H 2 | #define BOOLEANWINDOW_H 3 | 4 | #include 5 | 6 | class QLabel; 7 | class QLineEdit; 8 | class QTreeView; 9 | class BooleanModel; 10 | 11 | class BooleanWindow : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | BooleanWindow(); 17 | 18 | private slots: 19 | void booleanExpressionChanged(const QString &expr); 20 | 21 | private: 22 | QLabel *label; 23 | QLineEdit *lineEdit; 24 | BooleanModel *booleanModel; 25 | QTreeView *treeView; 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /chap10/booleanparser/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "booleanwindow.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | BooleanWindow window; 9 | window.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap10/booleanparser/node.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "booleanparser.h" 4 | 5 | Node::Node(Type type, const QString &str) 6 | { 7 | this->type = type; 8 | this->str = str; 9 | parent = 0; 10 | } 11 | 12 | Node::~Node() 13 | { 14 | qDeleteAll(children); 15 | } 16 | -------------------------------------------------------------------------------- /chap10/booleanparser/node.h: -------------------------------------------------------------------------------- 1 | #ifndef NODE_H 2 | #define NODE_H 3 | 4 | #include 5 | #include 6 | 7 | class Node 8 | { 9 | public: 10 | enum Type { Root, OrExpression, AndExpression, NotExpression, Atom, 11 | Identifier, Operator, Punctuator }; 12 | 13 | Node(Type type, const QString &str = ""); 14 | ~Node(); 15 | 16 | Type type; 17 | QString str; 18 | Node *parent; 19 | QList children; 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /chap10/cities/cities.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = citymodel.h 3 | SOURCES = citymodel.cpp \ 4 | main.cpp 5 | -------------------------------------------------------------------------------- /chap10/cities/citymodel.h: -------------------------------------------------------------------------------- 1 | #ifndef CITYMODEL_H 2 | #define CITYMODEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class CityModel : public QAbstractTableModel 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | CityModel(QObject *parent = 0); 14 | 15 | void setCities(const QStringList &cityNames); 16 | int rowCount(const QModelIndex &parent) const; 17 | int columnCount(const QModelIndex &parent) const; 18 | QVariant data(const QModelIndex &index, int role) const; 19 | bool setData(const QModelIndex &index, const QVariant &value, 20 | int role); 21 | QVariant headerData(int section, Qt::Orientation orientation, 22 | int role) const; 23 | Qt::ItemFlags flags(const QModelIndex &index) const; 24 | 25 | private: 26 | int offsetOf(int row, int column) const; 27 | 28 | QStringList cities; 29 | QVector distances; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /chap10/cities/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "citymodel.h" 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QApplication app(argc, argv); 10 | 11 | QStringList cities; 12 | cities << "Arvika" << "Boden" << "Eskilstuna" << "Falun" 13 | << "Filipstad" << "Halmstad" << "Helsingborg" << "Karlstad" 14 | << "Kiruna" << "Kramfors" << "Motala" << "Sandviken" 15 | << "Skara" << "Stockholm" << "Sundsvall" << "Trelleborg"; 16 | 17 | CityModel cityModel; 18 | cityModel.setCities(cities); 19 | 20 | QTableView tableView; 21 | tableView.setModel(&cityModel); 22 | tableView.setAlternatingRowColors(true); 23 | tableView.setWindowTitle(QObject::tr("Cities")); 24 | tableView.show(); 25 | 26 | return app.exec(); 27 | } 28 | -------------------------------------------------------------------------------- /chap10/colornames/colornames.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = colornamesdialog.h 3 | SOURCES = colornamesdialog.cpp \ 4 | main.cpp 5 | -------------------------------------------------------------------------------- /chap10/colornames/colornamesdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef COLORNAMESDIALOG_H 2 | #define COLORNAMESDIALOG_H 3 | 4 | #include 5 | 6 | class QComboBox; 7 | class QLabel; 8 | class QLineEdit; 9 | class QListView; 10 | class QSortFilterProxyModel; 11 | class QStringListModel; 12 | 13 | class ColorNamesDialog : public QDialog 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | ColorNamesDialog(QWidget *parent = 0); 19 | 20 | private slots: 21 | void reapplyFilter(); 22 | 23 | private: 24 | QStringListModel *sourceModel; 25 | QSortFilterProxyModel *proxyModel; 26 | QListView *listView; 27 | QLabel *filterLabel; 28 | QLabel *syntaxLabel; 29 | QLineEdit *filterLineEdit; 30 | QComboBox *syntaxComboBox; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /chap10/colornames/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "colornamesdialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | ColorNamesDialog dialog; 9 | dialog.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap10/coordinatesetter/coordinatesetter.h: -------------------------------------------------------------------------------- 1 | #ifndef COORDINATESETTER_H 2 | #define COORDINATESETTER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class QDialogButtonBox; 9 | class QTableWidget; 10 | 11 | class CoordinateSetter : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | CoordinateSetter(QList *coords, QWidget *parent = 0); 17 | 18 | void done(int result); 19 | 20 | private slots: 21 | void addRow(); 22 | 23 | private: 24 | QTableWidget *tableWidget; 25 | QDialogButtonBox *buttonBox; 26 | QList *coordinates; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /chap10/coordinatesetter/coordinatesetter.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = coordinatesetter.h 3 | SOURCES = coordinatesetter.cpp \ 4 | main.cpp 5 | -------------------------------------------------------------------------------- /chap10/coordinatesetter/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "coordinatesetter.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | 9 | QList coordinates; 10 | coordinates << QPointF(0.0, 0.9) 11 | << QPointF(0.2, 11.0) 12 | << QPointF(0.4, 15.4) 13 | << QPointF(0.6, 12.9) 14 | << QPointF(0.8, 8.5) 15 | << QPointF(1.0, 7.1) 16 | << QPointF(1.2, 4.0) 17 | << QPointF(1.4, 13.6) 18 | << QPointF(1.6, 22.2) 19 | << QPointF(1.8, 22.2); 20 | CoordinateSetter coordinateSetter(&coordinates); 21 | coordinateSetter.show(); 22 | 23 | return app.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /chap10/currencies/currencies.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = currencymodel.h 3 | SOURCES = currencymodel.cpp \ 4 | main.cpp 5 | -------------------------------------------------------------------------------- /chap10/currencies/currencymodel.h: -------------------------------------------------------------------------------- 1 | #ifndef CURRENCYMODEL_H 2 | #define CURRENCYMODEL_H 3 | 4 | #include 5 | #include 6 | 7 | class CurrencyModel : public QAbstractTableModel 8 | { 9 | public: 10 | CurrencyModel(QObject *parent = 0); 11 | 12 | void setCurrencyMap(const QMap &map); 13 | int rowCount(const QModelIndex &parent) const; 14 | int columnCount(const QModelIndex &parent) const; 15 | QVariant data(const QModelIndex &index, int role) const; 16 | QVariant headerData(int section, Qt::Orientation orientation, 17 | int role) const; 18 | 19 | private: 20 | QString currencyAt(int offset) const; 21 | 22 | QMap currencyMap; 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /chap10/currencies/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "currencymodel.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | 9 | QMap currencyMap; 10 | currencyMap.insert("AUD", 1.3259); 11 | currencyMap.insert("CHF", 1.2970); 12 | currencyMap.insert("CZK", 24.510); 13 | currencyMap.insert("DKK", 6.2168); 14 | currencyMap.insert("EUR", 0.8333); 15 | currencyMap.insert("GBP", 0.5661); 16 | currencyMap.insert("HKD", 7.7562); 17 | currencyMap.insert("JPY", 112.92); 18 | currencyMap.insert("NOK", 6.5200); 19 | currencyMap.insert("NZD", 1.4697); 20 | currencyMap.insert("SEK", 7.8180); 21 | currencyMap.insert("SGD", 1.6901); 22 | currencyMap.insert("USD", 1.0000); 23 | 24 | CurrencyModel currencyModel; 25 | currencyModel.setCurrencyMap(currencyMap); 26 | 27 | QTableView tableView; 28 | tableView.setModel(¤cyModel); 29 | tableView.setAlternatingRowColors(true); 30 | 31 | tableView.setWindowTitle(QObject::tr("Currencies")); 32 | tableView.show(); 33 | 34 | return app.exec(); 35 | } 36 | -------------------------------------------------------------------------------- /chap10/directoryviewer/directoryviewer.h: -------------------------------------------------------------------------------- 1 | #ifndef DIRECTORYVIEWER_H 2 | #define DIRECTORYVIEWER_H 3 | 4 | #include 5 | 6 | class QDialogButtonBox; 7 | class QDirModel; 8 | class QTreeView; 9 | 10 | class DirectoryViewer : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | DirectoryViewer(QWidget *parent = 0); 16 | 17 | private slots: 18 | void createDirectory(); 19 | void remove(); 20 | 21 | private: 22 | QTreeView *treeView; 23 | QDirModel *model; 24 | QDialogButtonBox *buttonBox; 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /chap10/directoryviewer/directoryviewer.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = directoryviewer.h 3 | SOURCES = directoryviewer.cpp \ 4 | main.cpp 5 | -------------------------------------------------------------------------------- /chap10/directoryviewer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "directoryviewer.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | DirectoryViewer directoryViewer; 9 | directoryViewer.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/flowchartsymbolpicker.h: -------------------------------------------------------------------------------- 1 | #ifndef FLOWCHARTSYMBOLPICKER_H 2 | #define FLOWCHARTSYMBOLPICKER_H 3 | 4 | #include 5 | #include 6 | 7 | class QDialogButtonBox; 8 | class QIcon; 9 | class QListWidget; 10 | 11 | class FlowChartSymbolPicker : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | FlowChartSymbolPicker(const QMap &symbolMap, 17 | QWidget *parent = 0); 18 | 19 | int selectedId() const { return id; } 20 | void done(int result); 21 | 22 | private: 23 | QIcon iconForSymbol(const QString &symbolName); 24 | 25 | QListWidget *listWidget; 26 | QDialogButtonBox *buttonBox; 27 | int id; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/flowchartsymbolpicker.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = flowchartsymbolpicker.h 3 | SOURCES = flowchartsymbolpicker.cpp \ 4 | main.cpp 5 | RESOURCES = flowchartsymbolpicker.qrc 6 | -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/flowchartsymbolpicker.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/data.png 4 | images/decision.png 5 | images/document.png 6 | images/manual-input.png 7 | images/manual-operation.png 8 | images/on-page-reference.png 9 | images/predefined-process.png 10 | images/preparation.png 11 | images/printer.png 12 | images/process.png 13 | 14 | 15 | -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/images/data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap10/flowchartsymbolpicker/images/data.png -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/images/decision.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap10/flowchartsymbolpicker/images/decision.png -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/images/document.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap10/flowchartsymbolpicker/images/document.png -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/images/manual-input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap10/flowchartsymbolpicker/images/manual-input.png -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/images/manual-operation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap10/flowchartsymbolpicker/images/manual-operation.png -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/images/on-page-reference.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap10/flowchartsymbolpicker/images/on-page-reference.png -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/images/predefined-process.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap10/flowchartsymbolpicker/images/predefined-process.png -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/images/preparation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap10/flowchartsymbolpicker/images/preparation.png -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/images/printer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap10/flowchartsymbolpicker/images/printer.png -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/images/process.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap10/flowchartsymbolpicker/images/process.png -------------------------------------------------------------------------------- /chap10/flowchartsymbolpicker/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "flowchartsymbolpicker.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | 9 | QMap symbolMap; 10 | symbolMap.insert(132, QObject::tr("Data")); 11 | symbolMap.insert(135, QObject::tr("Decision")); 12 | symbolMap.insert(137, QObject::tr("Document")); 13 | symbolMap.insert(138, QObject::tr("Manual Input")); 14 | symbolMap.insert(139, QObject::tr("Manual Operation")); 15 | symbolMap.insert(141, QObject::tr("On Page Reference")); 16 | symbolMap.insert(142, QObject::tr("Predefined Process")); 17 | symbolMap.insert(145, QObject::tr("Preparation")); 18 | symbolMap.insert(150, QObject::tr("Printer")); 19 | symbolMap.insert(152, QObject::tr("Process")); 20 | 21 | FlowChartSymbolPicker picker(symbolMap); 22 | picker.show(); 23 | 24 | return app.exec(); 25 | } 26 | -------------------------------------------------------------------------------- /chap10/settingsviewer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "settingsviewer.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | SettingsViewer settingsViewer; 9 | settingsViewer.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap10/settingsviewer/settingsviewer.h: -------------------------------------------------------------------------------- 1 | #ifndef SETTINGSVIEWER_H 2 | #define SETTINGSVIEWER_H 3 | 4 | #include 5 | 6 | class QDialogButtonBox; 7 | class QSettings; 8 | class QTreeWidget; 9 | class QTreeWidgetItem; 10 | 11 | class SettingsViewer : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | SettingsViewer(QWidget *parent = 0); 17 | 18 | private slots: 19 | void open(); 20 | 21 | private: 22 | void readSettings(); 23 | void addChildSettings(QSettings &settings, QTreeWidgetItem *item, 24 | const QString &group); 25 | 26 | QTreeWidget *treeWidget; 27 | QDialogButtonBox *buttonBox; 28 | 29 | QString organization; 30 | QString application; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /chap10/settingsviewer/settingsviewer.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = settingsviewer.h 3 | SOURCES = main.cpp \ 4 | settingsviewer.cpp 5 | -------------------------------------------------------------------------------- /chap10/teamleaders/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "teamleadersdialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | 9 | QStringList leaders; 10 | leaders << "Stooge Viller" << "Littleface" << "B-B Eyes" 11 | << "Pruneface" << "Mrs. Pruneface" << "The Brow" 12 | << "Vitamin Flintheart" << "Flattop Sr." << "Shakey" 13 | << "Breathless Mahoney" << "Mumbles" << "Shoulders" 14 | << "Sketch Paree"; 15 | 16 | TeamLeadersDialog dialog(leaders); 17 | dialog.show(); 18 | 19 | return app.exec(); 20 | } 21 | -------------------------------------------------------------------------------- /chap10/teamleaders/teamleaders.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = teamleadersdialog.h 3 | SOURCES = main.cpp \ 4 | teamleadersdialog.cpp 5 | -------------------------------------------------------------------------------- /chap10/teamleaders/teamleadersdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef TEAMLEADERSDIALOG_H 2 | #define TEAMLEADERSDIALOG_H 3 | 4 | #include 5 | 6 | class QDialogButtonBox; 7 | class QListView; 8 | class QStringListModel; 9 | 10 | class TeamLeadersDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | TeamLeadersDialog(const QStringList &leaders, QWidget *parent = 0); 16 | 17 | QStringList leaders() const; 18 | 19 | private slots: 20 | void insert(); 21 | void del(); 22 | 23 | private: 24 | QListView *listView; 25 | QDialogButtonBox *buttonBox; 26 | QStringListModel *model; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /chap10/trackeditor/trackdelegate.h: -------------------------------------------------------------------------------- 1 | #ifndef TRACKDELEGATE_H 2 | #define TRACKDELEGATE_H 3 | 4 | #include 5 | 6 | class TrackDelegate : public QItemDelegate 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | TrackDelegate(int durationColumn, QObject *parent = 0); 12 | 13 | void paint(QPainter *painter, const QStyleOptionViewItem &option, 14 | const QModelIndex &index) const; 15 | QWidget *createEditor(QWidget *parent, 16 | const QStyleOptionViewItem &option, 17 | const QModelIndex &index) const; 18 | void setEditorData(QWidget *editor, const QModelIndex &index) const; 19 | void setModelData(QWidget *editor, QAbstractItemModel *model, 20 | const QModelIndex &index) const; 21 | 22 | private slots: 23 | void commitAndCloseEditor(); 24 | 25 | private: 26 | int durationColumn; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /chap10/trackeditor/trackeditor.h: -------------------------------------------------------------------------------- 1 | #ifndef TRACKEDITOR_H 2 | #define TRACKEDITOR_H 3 | 4 | #include 5 | #include 6 | 7 | class QDialogButtonBox; 8 | class QTableWidget; 9 | 10 | class Track 11 | { 12 | public: 13 | Track(const QString &title = "", int duration = 0); 14 | 15 | QString title; 16 | int duration; 17 | }; 18 | 19 | class TrackEditor : public QDialog 20 | { 21 | Q_OBJECT 22 | 23 | public: 24 | TrackEditor(QList *tracks, QWidget *parent = 0); 25 | 26 | void done(int result); 27 | 28 | private slots: 29 | void addTrack(); 30 | 31 | private: 32 | QTableWidget *tableWidget; 33 | QDialogButtonBox *buttonBox; 34 | QList *tracks; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /chap10/trackeditor/trackeditor.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = trackdelegate.h \ 3 | trackeditor.h 4 | SOURCES = main.cpp \ 5 | trackdelegate.cpp \ 6 | trackeditor.cpp 7 | -------------------------------------------------------------------------------- /chap12/imageconverter/convertdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef CONVERTDIALOG_H 2 | #define CONVERTDIALOG_H 3 | 4 | #include 5 | #include 6 | 7 | #include "ui_convertdialog.h" 8 | 9 | class ConvertDialog : public QDialog, private Ui::ConvertDialog 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | ConvertDialog(QWidget *parent = 0); 15 | 16 | private slots: 17 | void on_browseButton_clicked(); 18 | void convertImage(); 19 | void updateOutputTextEdit(); 20 | void processFinished(int exitCode, QProcess::ExitStatus exitStatus); 21 | void processError(QProcess::ProcessError error); 22 | 23 | private: 24 | QProcess process; 25 | QString targetFile; 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /chap12/imageconverter/imageconverter.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = convertdialog.h 3 | SOURCES = convertdialog.cpp \ 4 | main.cpp 5 | FORMS = convertdialog.ui 6 | -------------------------------------------------------------------------------- /chap12/imageconverter/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "convertdialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | ConvertDialog dialog; 9 | dialog.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap12/imagespace/imagespace.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | qlonglong imageSpace(const QString &path) 5 | { 6 | QDir dir(path); 7 | qlonglong size = 0; 8 | 9 | QStringList filters; 10 | foreach (QByteArray format, QImageReader::supportedImageFormats()) 11 | filters += "*." + format; 12 | 13 | foreach (QString file, dir.entryList(filters, QDir::Files)) 14 | size += QFileInfo(dir, file).size(); 15 | 16 | foreach (QString subDir, dir.entryList(QDir::Dirs 17 | | QDir::NoDotAndDotDot)) 18 | size += imageSpace(path + QDir::separator() + subDir); 19 | 20 | return size; 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | QCoreApplication app(argc, argv); 26 | QStringList args = QCoreApplication::arguments(); 27 | 28 | QString path = QDir::currentPath(); 29 | if (args.count() > 1) 30 | path = args[1]; 31 | 32 | std::cout << "Space used by images in " << qPrintable(path) 33 | << " and its subdirectories is " 34 | << (imageSpace(path) / 1024) << " KB" << std::endl; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /chap12/imagespace/imagespace.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT = core gui xml 3 | CONFIG += console 4 | CONFIG -= app_bundle 5 | SOURCES = imagespace.cpp 6 | -------------------------------------------------------------------------------- /chap12/tidy/tidy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void tidyFile(QIODevice *inDevice, QIODevice *outDevice) 5 | { 6 | QTextStream in(inDevice); 7 | QTextStream out(outDevice); 8 | 9 | const int TabSize = 8; 10 | int endlCount = 0; 11 | int spaceCount = 0; 12 | int column = 0; 13 | QChar ch; 14 | 15 | while (!in.atEnd()) { 16 | in >> ch; 17 | 18 | if (ch == '\n') { 19 | ++endlCount; 20 | spaceCount = 0; 21 | column = 0; 22 | } else if (ch == '\t') { 23 | int size = TabSize - (column % TabSize); 24 | spaceCount += size; 25 | column += size; 26 | } else if (ch == ' ') { 27 | ++spaceCount; 28 | ++column; 29 | } else { 30 | while (endlCount > 0) { 31 | out << endl; 32 | --endlCount; 33 | column = 0; 34 | } 35 | while (spaceCount > 0) { 36 | out << ' '; 37 | --spaceCount; 38 | ++column; 39 | } 40 | out << ch; 41 | ++column; 42 | } 43 | } 44 | out << endl; 45 | } 46 | 47 | int main() 48 | { 49 | QFile inFile; 50 | QFile outFile; 51 | 52 | inFile.open(stdin, QFile::ReadOnly); 53 | outFile.open(stdout, QFile::WriteOnly); 54 | 55 | tidyFile(&inFile, &outFile); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /chap12/tidy/tidy.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT = core 3 | CONFIG += console 4 | CONFIG -= app_bundle 5 | SOURCES = tidy.cpp 6 | -------------------------------------------------------------------------------- /chap13/scooters/scooters.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += sql 3 | HEADERS = scooterwindow.h 4 | SOURCES = main.cpp \ 5 | scooterwindow.cpp 6 | -------------------------------------------------------------------------------- /chap13/scooters/scooterwindow.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "scooterwindow.h" 5 | 6 | ScooterWindow::ScooterWindow() 7 | { 8 | model = new QSqlTableModel(this); 9 | model->setTable("scooter"); 10 | model->setSort(Scooter_Name, Qt::AscendingOrder); 11 | model->setHeaderData(Scooter_Name, Qt::Horizontal, tr("Name")); 12 | model->setHeaderData(Scooter_MaxSpeed, Qt::Horizontal, tr("MPH")); 13 | model->setHeaderData(Scooter_MaxRange, Qt::Horizontal, tr("Miles")); 14 | model->setHeaderData(Scooter_Weight, Qt::Horizontal, tr("Lbs")); 15 | model->setHeaderData(Scooter_Description, Qt::Horizontal, 16 | tr("Description")); 17 | model->select(); 18 | 19 | view = new QTableView; 20 | view->setModel(model); 21 | view->setSelectionMode(QAbstractItemView::SingleSelection); 22 | view->setSelectionBehavior(QAbstractItemView::SelectRows); 23 | view->setColumnHidden(Scooter_Id, true); 24 | view->resizeColumnsToContents(); 25 | view->setEditTriggers(QAbstractItemView::NoEditTriggers); 26 | 27 | QHeaderView *header = view->horizontalHeader(); 28 | header->setStretchLastSection(true); 29 | 30 | QHBoxLayout *mainLayout = new QHBoxLayout; 31 | mainLayout->addWidget(view); 32 | setLayout(mainLayout); 33 | 34 | setWindowTitle(tr("Scooters")); 35 | } 36 | -------------------------------------------------------------------------------- /chap13/scooters/scooterwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SCOOTERWINDOW_H 2 | #define SCOOTERWINDOW_H 3 | 4 | #include 5 | 6 | class QSqlTableModel; 7 | class QTableView; 8 | 9 | enum { 10 | Scooter_Id = 0, 11 | Scooter_Name = 1, 12 | Scooter_MaxSpeed = 2, 13 | Scooter_MaxRange = 3, 14 | Scooter_Weight = 4, 15 | Scooter_Description = 5 16 | }; 17 | 18 | class ScooterWindow : public QWidget 19 | { 20 | Q_OBJECT 21 | 22 | public: 23 | ScooterWindow(); 24 | 25 | private: 26 | QSqlTableModel *model; 27 | QTableView *view; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /chap13/staffmanager/employeeform.h: -------------------------------------------------------------------------------- 1 | #ifndef EMPLOYEEFORM_H 2 | #define EMPLOYEEFORM_H 3 | 4 | #include 5 | 6 | class QComboBox; 7 | class QDataWidgetMapper; 8 | class QDateEdit; 9 | class QDialogButtonBox; 10 | class QLabel; 11 | class QLineEdit; 12 | class QPushButton; 13 | class QSqlRelationalTableModel; 14 | 15 | enum { 16 | Employee_Id = 0, 17 | Employee_Name = 1, 18 | Employee_DepartmentId = 2, 19 | Employee_Extension = 3, 20 | Employee_Email = 4, 21 | Employee_StartDate = 5 22 | }; 23 | 24 | class EmployeeForm : public QDialog 25 | { 26 | Q_OBJECT 27 | 28 | public: 29 | EmployeeForm(int id, QWidget *parent = 0); 30 | 31 | void done(int result); 32 | 33 | private slots: 34 | void addEmployee(); 35 | void deleteEmployee(); 36 | 37 | private: 38 | QSqlRelationalTableModel *tableModel; 39 | QDataWidgetMapper *mapper; 40 | QLabel *nameLabel; 41 | QLabel *departmentLabel; 42 | QLabel *extensionLabel; 43 | QLabel *emailLabel; 44 | QLabel *startDateLabel; 45 | QLineEdit *nameEdit; 46 | QComboBox *departmentComboBox; 47 | QLineEdit *extensionLineEdit; 48 | QLineEdit *emailEdit; 49 | QDateEdit *startDateEdit; 50 | QPushButton *firstButton; 51 | QPushButton *previousButton; 52 | QPushButton *nextButton; 53 | QPushButton *lastButton; 54 | QPushButton *addButton; 55 | QPushButton *deleteButton; 56 | QPushButton *closeButton; 57 | QDialogButtonBox *buttonBox; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /chap13/staffmanager/mainform.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINFORM_H 2 | #define MAINFORM_H 3 | 4 | #include 5 | 6 | class QDialogButtonBox; 7 | class QLabel; 8 | class QModelIndex; 9 | class QPushButton; 10 | class QSplitter; 11 | class QSqlRelationalTableModel; 12 | class QTableView; 13 | 14 | enum { 15 | Department_Id = 0, 16 | Department_Name = 1, 17 | Department_LocationId = 2 18 | }; 19 | 20 | class MainForm : public QWidget 21 | { 22 | Q_OBJECT 23 | 24 | public: 25 | MainForm(); 26 | 27 | private slots: 28 | void updateEmployeeView(); 29 | void addDepartment(); 30 | void deleteDepartment(); 31 | void editEmployees(); 32 | 33 | private: 34 | void createDepartmentPanel(); 35 | void createEmployeePanel(); 36 | 37 | QSqlRelationalTableModel *departmentModel; 38 | QSqlRelationalTableModel *employeeModel; 39 | QWidget *departmentPanel; 40 | QWidget *employeePanel; 41 | QLabel *departmentLabel; 42 | QLabel *employeeLabel; 43 | QTableView *departmentView; 44 | QTableView *employeeView; 45 | QSplitter *splitter; 46 | QPushButton *addButton; 47 | QPushButton *deleteButton; 48 | QPushButton *editButton; 49 | QPushButton *quitButton; 50 | QDialogButtonBox *buttonBox; 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /chap13/staffmanager/staffmanager.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += sql 3 | HEADERS = employeeform.h \ 4 | mainform.h 5 | SOURCES = employeeform.cpp \ 6 | main.cpp \ 7 | mainform.cpp 8 | -------------------------------------------------------------------------------- /chap14/imagepro/imagepro.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = imagewindow.h \ 3 | transactionthread.h 4 | SOURCES = imagewindow.cpp \ 5 | main.cpp \ 6 | transactionthread.cpp 7 | FORMS = resizedialog.ui 8 | -------------------------------------------------------------------------------- /chap14/imagepro/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "imagewindow.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | ImageWindow imageWin; 9 | imageWin.resize(400, 300); 10 | imageWin.show(); 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /chap14/semaphores/semaphores.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int DataSize = 100000; 5 | const int BufferSize = 4096; 6 | char buffer[BufferSize]; 7 | 8 | QSemaphore freeSpace(BufferSize); 9 | QSemaphore usedSpace(0); 10 | 11 | class Producer : public QThread 12 | { 13 | public: 14 | void run(); 15 | }; 16 | 17 | void Producer::run() 18 | { 19 | for (int i = 0; i < DataSize; ++i) { 20 | freeSpace.acquire(); 21 | buffer[i % BufferSize] = "ACGT"[uint(std::rand()) % 4]; 22 | usedSpace.release(); 23 | } 24 | } 25 | 26 | class Consumer : public QThread 27 | { 28 | public: 29 | void run(); 30 | }; 31 | 32 | void Consumer::run() 33 | { 34 | for (int i = 0; i < DataSize; ++i) { 35 | usedSpace.acquire(); 36 | std::cerr << buffer[i % BufferSize]; 37 | freeSpace.release(); 38 | } 39 | std::cerr << std::endl; 40 | } 41 | 42 | int main() 43 | { 44 | Producer producer; 45 | Consumer consumer; 46 | producer.start(); 47 | consumer.start(); 48 | producer.wait(); 49 | consumer.wait(); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /chap14/semaphores/semaphores.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console thread 3 | CONFIG -= app_bundle 4 | SOURCES = semaphores.cpp 5 | -------------------------------------------------------------------------------- /chap14/threads/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "threaddialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | ThreadDialog dialog; 9 | dialog.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap14/threads/thread.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "thread.h" 5 | 6 | Thread::Thread() 7 | { 8 | stopped = false; 9 | } 10 | 11 | void Thread::setMessage(const QString &message) 12 | { 13 | messageStr = message; 14 | } 15 | 16 | void Thread::run() 17 | { 18 | while (!stopped) 19 | std::cerr << qPrintable(messageStr); 20 | stopped = false; 21 | std::cerr << std::endl; 22 | } 23 | 24 | void Thread::stop() 25 | { 26 | stopped = true; 27 | } 28 | -------------------------------------------------------------------------------- /chap14/threads/thread.h: -------------------------------------------------------------------------------- 1 | #ifndef THREAD_H 2 | #define THREAD_H 3 | 4 | #include 5 | 6 | class Thread : public QThread 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | Thread(); 12 | 13 | void setMessage(const QString &message); 14 | void stop(); 15 | 16 | protected: 17 | void run(); 18 | 19 | private: 20 | QString messageStr; 21 | volatile bool stopped; 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /chap14/threads/threaddialog.h: -------------------------------------------------------------------------------- 1 | #ifndef THREADDIALOG_H 2 | #define THREADDIALOG_H 3 | 4 | #include 5 | 6 | #include "thread.h" 7 | 8 | class QPushButton; 9 | 10 | class ThreadDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | ThreadDialog(QWidget *parent = 0); 16 | 17 | protected: 18 | void closeEvent(QCloseEvent *event); 19 | 20 | private slots: 21 | void startOrStopThreadA(); 22 | void startOrStopThreadB(); 23 | 24 | private: 25 | Thread threadA; 26 | Thread threadB; 27 | QPushButton *threadAButton; 28 | QPushButton *threadBButton; 29 | QPushButton *quitButton; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /chap14/threads/threads.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console thread 3 | HEADERS = thread.h \ 4 | threaddialog.h 5 | SOURCES = main.cpp \ 6 | thread.cpp \ 7 | threaddialog.cpp 8 | -------------------------------------------------------------------------------- /chap14/waitconditions/waitconditions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int DataSize = 100000; 5 | const int BufferSize = 4096; 6 | char buffer[BufferSize]; 7 | 8 | QWaitCondition bufferIsNotFull; 9 | QWaitCondition bufferIsNotEmpty; 10 | QMutex mutex; 11 | int usedSpace = 0; 12 | 13 | class Producer : public QThread 14 | { 15 | public: 16 | void run(); 17 | }; 18 | 19 | void Producer::run() 20 | { 21 | for (int i = 0; i < DataSize; ++i) { 22 | mutex.lock(); 23 | while (usedSpace == BufferSize) 24 | bufferIsNotFull.wait(&mutex); 25 | buffer[i % BufferSize] = "ACGT"[uint(std::rand()) % 4]; 26 | ++usedSpace; 27 | bufferIsNotEmpty.wakeAll(); 28 | mutex.unlock(); 29 | } 30 | } 31 | 32 | class Consumer : public QThread 33 | { 34 | public: 35 | void run(); 36 | }; 37 | 38 | void Consumer::run() 39 | { 40 | for (int i = 0; i < DataSize; ++i) { 41 | mutex.lock(); 42 | while (usedSpace == 0) 43 | bufferIsNotEmpty.wait(&mutex); 44 | std::cerr << buffer[i % BufferSize]; 45 | --usedSpace; 46 | bufferIsNotFull.wakeAll(); 47 | mutex.unlock(); 48 | } 49 | std::cerr << std::endl; 50 | } 51 | 52 | int main() 53 | { 54 | Producer producer; 55 | Consumer consumer; 56 | producer.start(); 57 | consumer.start(); 58 | producer.wait(); 59 | consumer.wait(); 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /chap14/waitconditions/waitconditions.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console thread 3 | CONFIG -= app_bundle 4 | SOURCES = waitconditions.cpp 5 | -------------------------------------------------------------------------------- /chap15/ftpget/ftpget.h: -------------------------------------------------------------------------------- 1 | #ifndef FTPGET_H 2 | #define FTPGET_H 3 | 4 | #include 5 | #include 6 | 7 | class QUrl; 8 | 9 | class FtpGet : public QObject 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | FtpGet(QObject *parent = 0); 15 | 16 | bool getFile(const QUrl &url); 17 | 18 | signals: 19 | void done(); 20 | 21 | private slots: 22 | void ftpDone(bool error); 23 | 24 | private: 25 | QFtp ftp; 26 | QFile file; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /chap15/ftpget/ftpget.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT = core network 3 | CONFIG += console 4 | CONFIG -= app_bundle 5 | HEADERS = ftpget.h 6 | SOURCES = ftpget.cpp \ 7 | main.cpp 8 | -------------------------------------------------------------------------------- /chap15/ftpget/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "ftpget.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QCoreApplication app(argc, argv); 9 | QStringList args = QCoreApplication::arguments(); 10 | 11 | if (args.count() != 2) { 12 | std::cerr << "Usage: ftpget url" << std::endl 13 | << "Example:" << std::endl 14 | << " ftpget ftp://ftp.trolltech.com/mirrors" 15 | << std::endl; 16 | return 1; 17 | } 18 | 19 | FtpGet getter; 20 | if (!getter.getFile(QUrl(args[1]))) 21 | return 1; 22 | 23 | QObject::connect(&getter, SIGNAL(done()), &app, SLOT(quit())); 24 | 25 | return app.exec(); 26 | } 27 | -------------------------------------------------------------------------------- /chap15/httpget/httpget.h: -------------------------------------------------------------------------------- 1 | #ifndef HTTPGET_H 2 | #define HTTPGET_H 3 | 4 | #include 5 | #include 6 | 7 | class QUrl; 8 | 9 | class HttpGet : public QObject 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | HttpGet(QObject *parent = 0); 15 | 16 | bool getFile(const QUrl &url); 17 | 18 | signals: 19 | void done(); 20 | 21 | private slots: 22 | void httpDone(bool error); 23 | 24 | private: 25 | QHttp http; 26 | QFile file; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /chap15/httpget/httpget.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT = core network 3 | CONFIG += console 4 | CONFIG -= app_bundle 5 | HEADERS = httpget.h 6 | SOURCES = httpget.cpp \ 7 | main.cpp 8 | -------------------------------------------------------------------------------- /chap15/httpget/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "httpget.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QCoreApplication app(argc, argv); 9 | QStringList args = QCoreApplication::arguments(); 10 | 11 | if (args.count() != 2) { 12 | std::cerr << "Usage: httpget url" << std::endl 13 | << "Example:" << std::endl 14 | << " httpget http://doc.trolltech.com/index.html" 15 | << std::endl; 16 | return 1; 17 | } 18 | 19 | HttpGet getter; 20 | if (!getter.getFile(QUrl(args[1]))) 21 | return 1; 22 | 23 | QObject::connect(&getter, SIGNAL(done()), &app, SLOT(quit())); 24 | 25 | return app.exec(); 26 | } 27 | -------------------------------------------------------------------------------- /chap15/spider/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "spider.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QCoreApplication app(argc, argv); 9 | QStringList args = QCoreApplication::arguments(); 10 | 11 | if (args.count() != 2) { 12 | std::cerr << "Usage: spider url" << std::endl 13 | << "Example:" << std::endl 14 | << " spider ftp://ftp.trolltech.com/freebies/" 15 | << "leafnode" << std::endl; 16 | return 1; 17 | } 18 | 19 | Spider spider; 20 | if (!spider.getDirectory(QUrl(args[1]))) 21 | return 1; 22 | 23 | QObject::connect(&spider, SIGNAL(done()), &app, SLOT(quit())); 24 | 25 | return app.exec(); 26 | } 27 | -------------------------------------------------------------------------------- /chap15/spider/spider.h: -------------------------------------------------------------------------------- 1 | #ifndef SPIDER_H 2 | #define SPIDER_H 3 | 4 | #include 5 | #include 6 | 7 | class QFile; 8 | 9 | class Spider : public QObject 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | Spider(QObject *parent = 0); 15 | 16 | bool getDirectory(const QUrl &url); 17 | 18 | signals: 19 | void done(); 20 | 21 | private slots: 22 | void ftpDone(bool error); 23 | void ftpListInfo(const QUrlInfo &urlInfo); 24 | 25 | private: 26 | void processNextDirectory(); 27 | 28 | QFtp ftp; 29 | QList openedFiles; 30 | QString currentDir; 31 | QString currentLocalDir; 32 | QStringList pendingDirs; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /chap15/spider/spider.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT = core network 3 | CONFIG += console 4 | CONFIG -= app_bundle 5 | HEADERS = spider.h 6 | SOURCES = main.cpp \ 7 | spider.cpp 8 | -------------------------------------------------------------------------------- /chap15/tripplanner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "tripplanner.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | TripPlanner tripPlanner; 9 | tripPlanner.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap15/tripplanner/tripplanner.h: -------------------------------------------------------------------------------- 1 | #ifndef TRIPPLANNER_H 2 | #define TRIPPLANNER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "ui_tripplanner.h" 8 | 9 | class QPushButton; 10 | 11 | class TripPlanner : public QDialog, private Ui::TripPlanner 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | TripPlanner(QWidget *parent = 0); 17 | 18 | private slots: 19 | void connectToServer(); 20 | void sendRequest(); 21 | void updateTableWidget(); 22 | void stopSearch(); 23 | void connectionClosedByServer(); 24 | void error(); 25 | 26 | private: 27 | void closeConnection(); 28 | 29 | QPushButton *searchButton; 30 | QPushButton *stopButton; 31 | QTcpSocket tcpSocket; 32 | quint16 nextBlockSize; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /chap15/tripplanner/tripplanner.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += network 3 | HEADERS = tripplanner.h 4 | SOURCES = main.cpp \ 5 | tripplanner.cpp 6 | FORMS = tripplanner.ui 7 | -------------------------------------------------------------------------------- /chap15/tripserver/clientsocket.h: -------------------------------------------------------------------------------- 1 | #ifndef CLIENTSOCKET_H 2 | #define CLIENTSOCKET_H 3 | 4 | #include 5 | 6 | class QDate; 7 | class QTime; 8 | 9 | class ClientSocket : public QTcpSocket 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | ClientSocket(QObject *parent = 0); 15 | 16 | private slots: 17 | void readClient(); 18 | 19 | private: 20 | void generateRandomTrip(const QString &from, const QString &to, 21 | const QDate &date, const QTime &time); 22 | 23 | quint16 nextBlockSize; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /chap15/tripserver/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "tripserver.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | TripServer server; 10 | if (!server.listen(QHostAddress::Any, 6178)) { 11 | std::cerr << "Failed to bind to port" << std::endl; 12 | return 1; 13 | } 14 | 15 | QPushButton quitButton(QObject::tr("&Quit")); 16 | quitButton.setWindowTitle(QObject::tr("Trip Server")); 17 | QObject::connect(&quitButton, SIGNAL(clicked()), 18 | &app, SLOT(quit())); 19 | quitButton.show(); 20 | return app.exec(); 21 | } 22 | -------------------------------------------------------------------------------- /chap15/tripserver/tripserver.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "clientsocket.h" 4 | #include "tripserver.h" 5 | 6 | TripServer::TripServer(QObject *parent) 7 | : QTcpServer(parent) 8 | { 9 | } 10 | 11 | void TripServer::incomingConnection(int socketId) 12 | { 13 | ClientSocket *socket = new ClientSocket(this); 14 | socket->setSocketDescriptor(socketId); 15 | } 16 | -------------------------------------------------------------------------------- /chap15/tripserver/tripserver.h: -------------------------------------------------------------------------------- 1 | #ifndef TRIPSERVER_H 2 | #define TRIPSERVER_H 3 | 4 | #include 5 | 6 | class TripServer : public QTcpServer 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | TripServer(QObject *parent = 0); 12 | 13 | private: 14 | void incomingConnection(int socketId); 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /chap15/tripserver/tripserver.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += network 3 | HEADERS = clientsocket.h \ 4 | tripserver.h 5 | SOURCES = clientsocket.cpp \ 6 | main.cpp \ 7 | tripserver.cpp 8 | -------------------------------------------------------------------------------- /chap15/weatherballoon/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "weatherballoon.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | WeatherBalloon balloon; 9 | balloon.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap15/weatherballoon/weatherballoon.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "weatherballoon.h" 6 | 7 | WeatherBalloon::WeatherBalloon(QWidget *parent) 8 | : QPushButton(tr("Quit"), parent) 9 | { 10 | connect(this, SIGNAL(clicked()), this, SLOT(close())); 11 | connect(&timer, SIGNAL(timeout()), this, SLOT(sendDatagram())); 12 | 13 | timer.start(2 * 1000); 14 | 15 | setWindowTitle(tr("Weather Balloon")); 16 | } 17 | 18 | double WeatherBalloon::temperature() const 19 | { 20 | return -20.0 + (2.0 * std::rand() / (RAND_MAX + 1.0)); 21 | } 22 | 23 | double WeatherBalloon::humidity() const 24 | { 25 | return 20.0 + (2.0 * std::rand() / (RAND_MAX + 1.0)); 26 | } 27 | 28 | double WeatherBalloon::altitude() const 29 | { 30 | return 7000 + (100.0 * std::rand() / (RAND_MAX + 1.0)); 31 | } 32 | 33 | void WeatherBalloon::sendDatagram() 34 | { 35 | QByteArray datagram; 36 | QDataStream out(&datagram, QIODevice::WriteOnly); 37 | out.setVersion(QDataStream::Qt_4_3); 38 | out << QDateTime::currentDateTime() << temperature() << humidity() 39 | << altitude(); 40 | 41 | udpSocket.writeDatagram(datagram, QHostAddress::LocalHost, 5824); 42 | } 43 | -------------------------------------------------------------------------------- /chap15/weatherballoon/weatherballoon.h: -------------------------------------------------------------------------------- 1 | #ifndef WEATHERBALLOON_H 2 | #define WEATHERBALLOON_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class WeatherBalloon : public QPushButton 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | WeatherBalloon(QWidget *parent = 0); 14 | 15 | double temperature() const; 16 | double humidity() const; 17 | double altitude() const; 18 | 19 | private slots: 20 | void sendDatagram(); 21 | 22 | private: 23 | QUdpSocket udpSocket; 24 | QTimer timer; 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /chap15/weatherballoon/weatherballoon.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += network 3 | HEADERS = weatherballoon.h 4 | SOURCES = main.cpp \ 5 | weatherballoon.cpp 6 | -------------------------------------------------------------------------------- /chap15/weatherstation/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "weatherstation.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | WeatherStation station; 9 | station.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap15/weatherstation/weatherstation.h: -------------------------------------------------------------------------------- 1 | #ifndef WEATHERSTATION_H 2 | #define WEATHERSTATION_H 3 | 4 | #include 5 | #include 6 | 7 | class QLabel; 8 | class QLineEdit; 9 | 10 | class WeatherStation : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | WeatherStation(QWidget *parent = 0); 16 | 17 | private slots: 18 | void processPendingDatagrams(); 19 | 20 | private: 21 | QUdpSocket udpSocket; 22 | 23 | QLabel *dateLabel; 24 | QLabel *timeLabel; 25 | QLabel *temperatureLabel; 26 | QLabel *humidityLabel; 27 | QLabel *altitudeLabel; 28 | QLineEdit *dateLineEdit; 29 | QLineEdit *timeLineEdit; 30 | QLineEdit *temperatureLineEdit; 31 | QLineEdit *humidityLineEdit; 32 | QLineEdit *altitudeLineEdit; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /chap15/weatherstation/weatherstation.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += network 3 | HEADERS = weatherstation.h 4 | SOURCES = main.cpp \ 5 | weatherstation.cpp 6 | -------------------------------------------------------------------------------- /chap16/domparser/domparser.h: -------------------------------------------------------------------------------- 1 | #ifndef DOMPARSER_H 2 | #define DOMPARSER_H 3 | 4 | class QDomElement; 5 | class QString; 6 | class QTreeWidget; 7 | class QTreeWidgetItem; 8 | 9 | class DomParser 10 | { 11 | public: 12 | DomParser(QTreeWidget *tree); 13 | 14 | bool readFile(const QString &fileName); 15 | 16 | private: 17 | void parseBookindexElement(const QDomElement &element); 18 | void parseEntryElement(const QDomElement &element, 19 | QTreeWidgetItem *parent); 20 | void parsePageElement(const QDomElement &element, 21 | QTreeWidgetItem *parent); 22 | 23 | QTreeWidget *treeWidget; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /chap16/domparser/domparser.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += xml 3 | CONFIG += console 4 | HEADERS = domparser.h 5 | SOURCES = domparser.cpp \ 6 | main.cpp 7 | -------------------------------------------------------------------------------- /chap16/domparser/in1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 5 | 34-35 6 | 307-308 7 | 8 | 9 | 10 | 115 11 | 244 12 | 13 | 14 | 9 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /chap16/domparser/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "domparser.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | QStringList args = QApplication::arguments(); 10 | 11 | if (args.count() < 2) { 12 | std::cerr << "Usage: domparser file1.xml..." << std::endl; 13 | return 1; 14 | } 15 | 16 | QStringList labels; 17 | labels << QObject::tr("Terms") << QObject::tr("Pages"); 18 | 19 | QTreeWidget treeWidget; 20 | treeWidget.setHeaderLabels(labels); 21 | treeWidget.header()->setResizeMode(QHeaderView::Stretch); 22 | treeWidget.setWindowTitle(QObject::tr("DOM Parser")); 23 | treeWidget.show(); 24 | 25 | DomParser parser(&treeWidget); 26 | for (int i = 1; i < args.count(); ++i) 27 | parser.readFile(args[i]); 28 | 29 | return app.exec(); 30 | } 31 | -------------------------------------------------------------------------------- /chap16/saxhandler/in1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 5 | 34-35 6 | 307-308 7 | 8 | 9 | 10 | 115 11 | 244 12 | 13 | 14 | 9 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /chap16/saxhandler/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "saxhandler.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | QStringList args = QApplication::arguments(); 10 | 11 | if (args.count() < 2) { 12 | std::cerr << "Usage: saxhandler file1.xml..." << std::endl; 13 | return 1; 14 | } 15 | 16 | QStringList labels; 17 | labels << QObject::tr("Terms") << QObject::tr("Pages"); 18 | 19 | QTreeWidget treeWidget; 20 | treeWidget.setHeaderLabels(labels); 21 | treeWidget.header()->setResizeMode(QHeaderView::Stretch); 22 | treeWidget.setWindowTitle(QObject::tr("SAX Handler")); 23 | treeWidget.show(); 24 | 25 | SaxHandler handler(&treeWidget); 26 | for (int i = 1; i < args.count(); ++i) 27 | handler.readFile(args[i]); 28 | 29 | return app.exec(); 30 | } 31 | -------------------------------------------------------------------------------- /chap16/saxhandler/saxhandler.h: -------------------------------------------------------------------------------- 1 | #ifndef SAXHANDLER_H 2 | #define SAXHANDLER_H 3 | 4 | #include 5 | 6 | class QTreeWidget; 7 | class QTreeWidgetItem; 8 | 9 | class SaxHandler : public QXmlDefaultHandler 10 | { 11 | public: 12 | SaxHandler(QTreeWidget *tree); 13 | 14 | bool readFile(const QString &fileName); 15 | 16 | protected: 17 | bool startElement(const QString &namespaceURI, 18 | const QString &localName, 19 | const QString &qName, 20 | const QXmlAttributes &attributes); 21 | bool endElement(const QString &namespaceURI, 22 | const QString &localName, 23 | const QString &qName); 24 | bool characters(const QString &str); 25 | bool fatalError(const QXmlParseException &exception); 26 | 27 | private: 28 | QTreeWidget *treeWidget; 29 | QTreeWidgetItem *currentItem; 30 | QString currentText; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /chap16/saxhandler/saxhandler.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += xml 3 | CONFIG += console 4 | HEADERS = saxhandler.h 5 | SOURCES = main.cpp \ 6 | saxhandler.cpp 7 | -------------------------------------------------------------------------------- /chap16/xmlstreamreader/in1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 5 | 34-35 6 | 307-308 7 | 8 | 9 | 10 | 115 11 | 244 12 | 13 | 14 | 9 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /chap16/xmlstreamreader/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "xmlstreamreader.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | QStringList args = QApplication::arguments(); 10 | 11 | if (args.count() < 2) { 12 | std::cerr << "Usage: xmlstreamreader file1.xml..." 13 | << std::endl; 14 | return 1; 15 | } 16 | 17 | QStringList labels; 18 | labels << QObject::tr("Terms") << QObject::tr("Pages"); 19 | 20 | QTreeWidget treeWidget; 21 | treeWidget.setHeaderLabels(labels); 22 | treeWidget.header()->setResizeMode(QHeaderView::Stretch); 23 | treeWidget.setWindowTitle(QObject::tr("XML Stream Reader")); 24 | treeWidget.show(); 25 | 26 | XmlStreamReader reader(&treeWidget); 27 | for (int i = 1; i < args.count(); ++i) 28 | reader.readFile(args[i]); 29 | 30 | return app.exec(); 31 | } 32 | -------------------------------------------------------------------------------- /chap16/xmlstreamreader/xmlstreamreader.h: -------------------------------------------------------------------------------- 1 | #ifndef XMLSTREAMREADER_H 2 | #define XMLSTREAMREADER_H 3 | 4 | #include 5 | 6 | class QTreeWidget; 7 | class QTreeWidgetItem; 8 | 9 | class XmlStreamReader 10 | { 11 | public: 12 | XmlStreamReader(QTreeWidget *tree); 13 | 14 | bool readFile(const QString &fileName); 15 | 16 | private: 17 | void readBookindexElement(); 18 | void readEntryElement(QTreeWidgetItem *parent); 19 | void readPageElement(QTreeWidgetItem *parent); 20 | void skipUnknownElement(); 21 | 22 | QTreeWidget *treeWidget; 23 | QXmlStreamReader reader; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /chap16/xmlstreamreader/xmlstreamreader.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += xml 3 | HEADERS = xmlstreamreader.h 4 | SOURCES = main.cpp \ 5 | xmlstreamreader.cpp 6 | -------------------------------------------------------------------------------- /chap16/xmlstreamwriter/xmlstreamwriter.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += xml 3 | SOURCES = xmlstreamwriter.cpp 4 | -------------------------------------------------------------------------------- /chap19/bronze/bronze.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = bronzedialog.h \ 3 | bronzestyle.h 4 | SOURCES = bronzedialog.cpp \ 5 | bronzestyle.cpp \ 6 | main.cpp 7 | RESOURCES = bronze.qrc 8 | -------------------------------------------------------------------------------- /chap19/bronze/bronze.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/background.png 4 | images/checkmark.png 5 | images/checkmark-disabled.png 6 | images/checkmark-partial.png 7 | 8 | 9 | -------------------------------------------------------------------------------- /chap19/bronze/bronzedialog.h: -------------------------------------------------------------------------------- 1 | #ifndef BRONZEDIALOG_H 2 | #define BRONZEDIALOG_H 3 | 4 | #include 5 | 6 | class QCheckBox; 7 | class QDateEdit; 8 | class QDialogButtonBox; 9 | class QDoubleSpinBox; 10 | class QLabel; 11 | class QSpinBox; 12 | class QTimeEdit; 13 | class QTreeWidget; 14 | 15 | class BronzeDialog : public QDialog 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | BronzeDialog(QWidget *parent = 0); 21 | 22 | private slots: 23 | void editableStateChanged(bool editable); 24 | 25 | private: 26 | void populateAgendaTreeWidget(); 27 | 28 | QLabel *dateLabel; 29 | QLabel *timeLabel; 30 | QLabel *durationLabel; 31 | QLabel *priceLabel; 32 | QLabel *agendaLabel; 33 | QDateEdit *dateEdit; 34 | QTimeEdit *timeEdit; 35 | QSpinBox *durationSpinBox; 36 | QDoubleSpinBox *priceSpinBox; 37 | QCheckBox *reminderCheckBox; 38 | QCheckBox *editableCheckBox; 39 | QTreeWidget *agendaTreeWidget; 40 | QDialogButtonBox *buttonBox; 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /chap19/bronze/images/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap19/bronze/images/background.png -------------------------------------------------------------------------------- /chap19/bronze/images/checkmark-disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap19/bronze/images/checkmark-disabled.png -------------------------------------------------------------------------------- /chap19/bronze/images/checkmark-partial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap19/bronze/images/checkmark-partial.png -------------------------------------------------------------------------------- /chap19/bronze/images/checkmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap19/bronze/images/checkmark.png -------------------------------------------------------------------------------- /chap19/bronze/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "bronzedialog.h" 4 | #include "bronzestyle.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | QApplication::setStyle(new BronzeStyle); 10 | BronzeDialog dialog; 11 | dialog.layout()->setSpacing(7); 12 | dialog.layout()->setMargin(7); 13 | dialog.show(); 14 | return app.exec(); 15 | } 16 | -------------------------------------------------------------------------------- /chap19/candy/candy.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = candydialog.h 3 | SOURCES = candydialog.cpp \ 4 | main.cpp 5 | RESOURCES = candy.qrc 6 | -------------------------------------------------------------------------------- /chap19/candy/candy.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qss/candy.qss 4 | images/background.png 5 | images/button.png 6 | images/button-hover.png 7 | images/button-pressed.png 8 | images/down-arrow.png 9 | 10 | 11 | -------------------------------------------------------------------------------- /chap19/candy/candydialog.h: -------------------------------------------------------------------------------- 1 | #ifndef CANDYDIALOG_H 2 | #define CANDYDIALOG_H 3 | 4 | #include 5 | 6 | class QCheckBox; 7 | class QComboBox; 8 | class QDialogButtonBox; 9 | class QLabel; 10 | class QLineEdit; 11 | class QListWidget; 12 | 13 | class CandyDialog : public QDialog 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | CandyDialog(QWidget *parent = 0); 19 | 20 | private: 21 | QLabel *nameLabel; 22 | QLabel *passwordLabel; 23 | QLabel *countryLabel; 24 | QLabel *professionLabel; 25 | QComboBox *nameComboBox; 26 | QLineEdit *passwordLineEdit; 27 | QComboBox *countryComboBox; 28 | QListWidget *professionListWidget; 29 | QCheckBox *acceptCheckBox; 30 | QDialogButtonBox *buttonBox; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /chap19/candy/images/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap19/candy/images/background.png -------------------------------------------------------------------------------- /chap19/candy/images/button-hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap19/candy/images/button-hover.png -------------------------------------------------------------------------------- /chap19/candy/images/button-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap19/candy/images/button-pressed.png -------------------------------------------------------------------------------- /chap19/candy/images/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap19/candy/images/button.png -------------------------------------------------------------------------------- /chap19/candy/images/down-arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap19/candy/images/down-arrow.png -------------------------------------------------------------------------------- /chap19/candy/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "candydialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | QApplication::setStyle(new QPlastiqueStyle); 9 | 10 | QFile file(":/qss/candy.qss"); 11 | file.open(QFile::ReadOnly); 12 | app.setStyleSheet(file.readAll()); 13 | 14 | CandyDialog dialog; 15 | dialog.show(); 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /chap20/teapots/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "teapots.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | 10 | if (!QGLFormat::hasOpenGL()) { 11 | std::cerr << "This system has no OpenGL support" << std::endl; 12 | return 1; 13 | } 14 | 15 | if (!QGLFramebufferObject::hasOpenGLFramebufferObjects()) { 16 | std::cerr << "This system has no framebuffer object support" 17 | << std::endl; 18 | return 1; 19 | } 20 | 21 | Teapots teapots; 22 | teapots.setWindowTitle(QObject::tr("Teapots")); 23 | teapots.resize(400, 400); 24 | teapots.show(); 25 | 26 | return app.exec(); 27 | } 28 | -------------------------------------------------------------------------------- /chap20/teapots/teapots.h: -------------------------------------------------------------------------------- 1 | #ifndef TEAPOTS_H 2 | #define TEAPOTS_H 3 | 4 | #include 5 | #include 6 | 7 | class Teapots : public QGLWidget 8 | { 9 | Q_OBJECT 10 | 11 | public: 12 | Teapots(QWidget *parent = 0); 13 | ~Teapots(); 14 | 15 | protected: 16 | void initializeGL(); 17 | void resizeGL(int width, int height); 18 | void paintGL(); 19 | void mousePressEvent(QMouseEvent *event); 20 | void mouseMoveEvent(QMouseEvent *event); 21 | void mouseReleaseEvent(QMouseEvent *event); 22 | 23 | private: 24 | void createGLTeapotObject(); 25 | void drawTeapot(GLfloat x, GLfloat y, GLfloat ambientR, 26 | GLfloat ambientG, GLfloat ambientB, 27 | GLfloat diffuseR, GLfloat diffuseG, 28 | GLfloat diffuseB, GLfloat specularR, 29 | GLfloat specularG, GLfloat specularB, 30 | GLfloat shininess); 31 | void drawTeapots(); 32 | 33 | QGLFramebufferObject *fbObject; 34 | GLuint glTeapotObject; 35 | QPoint rubberBandCorner1; 36 | QPoint rubberBandCorner2; 37 | bool rubberBandIsShown; 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /chap20/teapots/teapots.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += opengl 3 | CONFIG += console 4 | HEADERS = teapots.h 5 | SOURCES = main.cpp \ 6 | teapots.cpp 7 | -------------------------------------------------------------------------------- /chap20/tetrahedron/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "tetrahedron.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | 10 | if (!QGLFormat::hasOpenGL()) { 11 | std::cerr << "This system has no OpenGL support" << std::endl; 12 | return 1; 13 | } 14 | 15 | Tetrahedron tetrahedron; 16 | tetrahedron.setWindowTitle(QObject::tr("Tetrahedron")); 17 | tetrahedron.resize(300, 300); 18 | tetrahedron.show(); 19 | 20 | return app.exec(); 21 | } 22 | -------------------------------------------------------------------------------- /chap20/tetrahedron/tetrahedron.h: -------------------------------------------------------------------------------- 1 | #ifndef TETRAHEDRON_H 2 | #define TETRAHEDRON_H 3 | 4 | #include 5 | 6 | class Tetrahedron : public QGLWidget 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | Tetrahedron(QWidget *parent = 0); 12 | 13 | protected: 14 | void initializeGL(); 15 | void resizeGL(int width, int height); 16 | void paintGL(); 17 | void mousePressEvent(QMouseEvent *event); 18 | void mouseMoveEvent(QMouseEvent *event); 19 | void mouseDoubleClickEvent(QMouseEvent *event); 20 | 21 | private: 22 | void draw(); 23 | int faceAtPosition(const QPoint &pos); 24 | 25 | GLfloat rotationX; 26 | GLfloat rotationY; 27 | GLfloat rotationZ; 28 | QColor faceColors[4]; 29 | QPoint lastPos; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /chap20/tetrahedron/tetrahedron.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += opengl 3 | CONFIG += console 4 | HEADERS = tetrahedron.h 5 | SOURCES = main.cpp \ 6 | tetrahedron.cpp 7 | -------------------------------------------------------------------------------- /chap20/vowelcube/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "vowelcube.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | 10 | if (!QGLFormat::hasOpenGL()) { 11 | std::cerr << "This system has no OpenGL support" << std::endl; 12 | return 1; 13 | } 14 | 15 | VowelCube cube; 16 | cube.setWindowTitle(QObject::tr("Vowel Cube")); 17 | cube.setMinimumSize(200, 200); 18 | cube.resize(450, 450); 19 | cube.show(); 20 | 21 | return app.exec(); 22 | } 23 | -------------------------------------------------------------------------------- /chap20/vowelcube/vowelcube.h: -------------------------------------------------------------------------------- 1 | #ifndef VOWELCUBE_H 2 | #define VOWELCUBE_H 3 | 4 | #include 5 | #include 6 | 7 | class VowelCube : public QGLWidget 8 | { 9 | Q_OBJECT 10 | 11 | public: 12 | VowelCube(QWidget *parent = 0); 13 | ~VowelCube(); 14 | 15 | protected: 16 | void paintEvent(QPaintEvent *event); 17 | void mousePressEvent(QMouseEvent *event); 18 | void mouseMoveEvent(QMouseEvent *event); 19 | void wheelEvent(QWheelEvent *event); 20 | 21 | private: 22 | void createGradient(); 23 | void createGLObject(); 24 | void drawBackground(QPainter *painter); 25 | void drawCube(); 26 | void drawLegend(QPainter *painter); 27 | 28 | GLuint glObject; 29 | QRadialGradient gradient; 30 | GLfloat rotationX; 31 | GLfloat rotationY; 32 | GLfloat rotationZ; 33 | GLfloat scaling; 34 | QPoint lastPos; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /chap20/vowelcube/vowelcube.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += opengl 3 | CONFIG += console 4 | HEADERS = vowelcube.h 5 | SOURCES = main.cpp \ 6 | vowelcube.cpp 7 | -------------------------------------------------------------------------------- /chap21/basiceffectsplugin/basiceffectsplugin.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICEFFECTSPLUGIN_H 2 | #define BASICEFFECTSPLUGIN_H 3 | 4 | #include 5 | 6 | #include "../textart/textartinterface.h" 7 | 8 | class BasicEffectsPlugin : public QObject, public TextArtInterface 9 | { 10 | Q_OBJECT 11 | Q_INTERFACES(TextArtInterface) 12 | 13 | public: 14 | QStringList effects() const; 15 | QPixmap applyEffect(const QString &effect, const QString &text, 16 | const QFont &font, const QSize &size, 17 | const QPen &pen, const QBrush &brush); 18 | }; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /chap21/basiceffectsplugin/basiceffectsplugin.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | CONFIG += plugin 3 | HEADERS = ../textart/textartinterface.h \ 4 | basiceffectsplugin.h 5 | SOURCES = basiceffectsplugin.cpp 6 | DESTDIR = ../textart/plugins 7 | -------------------------------------------------------------------------------- /chap21/bronze/bronze.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = bronzedialog.h \ 3 | bronzestyle.h 4 | SOURCES = bronzedialog.cpp \ 5 | bronzestyle.cpp \ 6 | main.cpp 7 | RESOURCES = bronze.qrc 8 | -------------------------------------------------------------------------------- /chap21/bronze/bronze.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/background.png 4 | images/checkmark.png 5 | images/checkmark-disabled.png 6 | images/checkmark-partial.png 7 | 8 | 9 | -------------------------------------------------------------------------------- /chap21/bronze/bronzedialog.h: -------------------------------------------------------------------------------- 1 | #ifndef BRONZEDIALOG_H 2 | #define BRONZEDIALOG_H 3 | 4 | #include 5 | 6 | class QCheckBox; 7 | class QDateEdit; 8 | class QDialogButtonBox; 9 | class QDoubleSpinBox; 10 | class QLabel; 11 | class QSpinBox; 12 | class QTimeEdit; 13 | class QTreeWidget; 14 | 15 | class BronzeDialog : public QDialog 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | BronzeDialog(QWidget *parent = 0); 21 | 22 | private slots: 23 | void editableStateChanged(bool editable); 24 | 25 | private: 26 | void populateAgendaTreeWidget(); 27 | 28 | QLabel *dateLabel; 29 | QLabel *timeLabel; 30 | QLabel *durationLabel; 31 | QLabel *priceLabel; 32 | QLabel *agendaLabel; 33 | QDateEdit *dateEdit; 34 | QTimeEdit *timeEdit; 35 | QSpinBox *durationSpinBox; 36 | QDoubleSpinBox *priceSpinBox; 37 | QCheckBox *reminderCheckBox; 38 | QCheckBox *editableCheckBox; 39 | QTreeWidget *agendaTreeWidget; 40 | QDialogButtonBox *buttonBox; 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /chap21/bronze/images/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap21/bronze/images/background.png -------------------------------------------------------------------------------- /chap21/bronze/images/checkmark-disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap21/bronze/images/checkmark-disabled.png -------------------------------------------------------------------------------- /chap21/bronze/images/checkmark-partial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap21/bronze/images/checkmark-partial.png -------------------------------------------------------------------------------- /chap21/bronze/images/checkmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap21/bronze/images/checkmark.png -------------------------------------------------------------------------------- /chap21/bronze/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "bronzedialog.h" 4 | #include "bronzestyle.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication app(argc, argv); 9 | QApplication::setStyle(new BronzeStyle); 10 | BronzeDialog dialog; 11 | dialog.layout()->setSpacing(7); 12 | dialog.layout()->setMargin(7); 13 | dialog.show(); 14 | return app.exec(); 15 | } 16 | -------------------------------------------------------------------------------- /chap21/bronzestyleplugin/bronzestyleplugin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "bronzestyleplugin.h" 4 | #include "../bronze/bronzestyle.h" 5 | 6 | QStringList BronzeStylePlugin::keys() const 7 | { 8 | return QStringList() << "Bronze"; 9 | } 10 | 11 | QStyle *BronzeStylePlugin::create(const QString &key) 12 | { 13 | if (key.toLower() == "bronze") 14 | return new BronzeStyle; 15 | return 0; 16 | } 17 | 18 | Q_EXPORT_PLUGIN2(bronzestyleplugin, BronzeStylePlugin) 19 | -------------------------------------------------------------------------------- /chap21/bronzestyleplugin/bronzestyleplugin.h: -------------------------------------------------------------------------------- 1 | #ifndef BRONZESTYLEPLUGIN_H 2 | #define BRONZESTYLEPLUGIN_H 3 | 4 | #include 5 | 6 | class BronzeStylePlugin : public QStylePlugin 7 | { 8 | public: 9 | QStringList keys() const; 10 | QStyle *create(const QString &key); 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /chap21/bronzestyleplugin/bronzestyleplugin.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | CONFIG += plugin 3 | HEADERS = ../bronze/bronzestyle.h \ 4 | bronzestyleplugin.h 5 | SOURCES = ../bronze/bronzestyle.cpp \ 6 | bronzestyleplugin.cpp 7 | RESOURCES = ../bronze/bronze.qrc 8 | DESTDIR = $$[QT_INSTALL_PLUGINS]/styles 9 | -------------------------------------------------------------------------------- /chap21/bronzestyleplugin/images/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap21/bronzestyleplugin/images/background.png -------------------------------------------------------------------------------- /chap21/bronzestyleplugin/images/checkmark-disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap21/bronzestyleplugin/images/checkmark-disabled.png -------------------------------------------------------------------------------- /chap21/bronzestyleplugin/images/checkmark-partial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap21/bronzestyleplugin/images/checkmark-partial.png -------------------------------------------------------------------------------- /chap21/bronzestyleplugin/images/checkmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap21/bronzestyleplugin/images/checkmark.png -------------------------------------------------------------------------------- /chap21/cursorplugin/cursorhandler.h: -------------------------------------------------------------------------------- 1 | #ifndef CURIMAGEHANDLER_H 2 | #define CURIMAGEHANDLER_H 3 | 4 | #include 5 | 6 | class CursorHandler : public QImageIOHandler 7 | { 8 | public: 9 | CursorHandler(); 10 | 11 | bool canRead() const; 12 | bool read(QImage *image); 13 | bool jumpToNextImage(); 14 | int currentImageNumber() const; 15 | int imageCount() const; 16 | 17 | private: 18 | enum State { BeforeHeader, BeforeImage, AfterLastImage, Error }; 19 | 20 | void readHeaderIfNecessary() const; 21 | QBitArray readBitmap(int width, int height, QDataStream &in) const; 22 | void enterErrorState() const; 23 | 24 | mutable State state; 25 | mutable int currentImageNo; 26 | mutable int numImages; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /chap21/cursorplugin/cursorplugin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "cursorhandler.h" 4 | #include "cursorplugin.h" 5 | 6 | QStringList CursorPlugin::keys() const 7 | { 8 | return QStringList() << "cur"; 9 | } 10 | 11 | QImageIOPlugin::Capabilities 12 | CursorPlugin::capabilities(QIODevice *device, 13 | const QByteArray &format) const 14 | { 15 | if (format == "cur") 16 | return CanRead; 17 | 18 | if (format.isEmpty()) { 19 | CursorHandler handler; 20 | handler.setDevice(device); 21 | if (handler.canRead()) 22 | return CanRead; 23 | } 24 | 25 | return 0; 26 | } 27 | 28 | QImageIOHandler *CursorPlugin::create(QIODevice *device, 29 | const QByteArray &format) const 30 | { 31 | CursorHandler *handler = new CursorHandler; 32 | handler->setDevice(device); 33 | handler->setFormat(format); 34 | return handler; 35 | } 36 | 37 | Q_EXPORT_PLUGIN2(cursorplugin, CursorPlugin) 38 | -------------------------------------------------------------------------------- /chap21/cursorplugin/cursorplugin.h: -------------------------------------------------------------------------------- 1 | #ifndef CURSORPLUGIN_H 2 | #define CURSORPLUGIN_H 3 | 4 | #include 5 | 6 | class CursorPlugin : public QImageIOPlugin 7 | { 8 | public: 9 | QStringList keys() const; 10 | Capabilities capabilities(QIODevice *device, 11 | const QByteArray &format) const; 12 | QImageIOHandler *create(QIODevice *device, 13 | const QByteArray &format) const; 14 | }; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /chap21/cursorplugin/cursorplugin.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | CONFIG += plugin 3 | HEADERS = cursorhandler.h \ 4 | cursorplugin.h 5 | SOURCES = cursorhandler.cpp \ 6 | cursorplugin.cpp 7 | DESTDIR = $$[QT_INSTALL_PLUGINS]/imageformats 8 | -------------------------------------------------------------------------------- /chap21/cursorplugin/cursors/cross.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap21/cursorplugin/cursors/cross.cur -------------------------------------------------------------------------------- /chap21/cursorplugin/cursors/move.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap21/cursorplugin/cursors/move.cur -------------------------------------------------------------------------------- /chap21/cursorplugin/cursors/whatsthis.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap21/cursorplugin/cursors/whatsthis.cur -------------------------------------------------------------------------------- /chap21/extraeffectsplugin/extraeffectsplugin.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICEFFECTSPLUGIN_H 2 | #define BASICEFFECTSPLUGIN_H 3 | 4 | #include 5 | 6 | #include "../textart/textartinterface.h" 7 | 8 | class ExtraEffectsPlugin : public QObject, public TextArtInterface 9 | { 10 | Q_OBJECT 11 | Q_INTERFACES(TextArtInterface) 12 | 13 | public: 14 | QStringList effects() const; 15 | QPixmap applyEffect(const QString &effect, const QString &text, 16 | const QFont &font, const QSize &size, 17 | const QPen &pen, const QBrush &brush); 18 | }; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /chap21/extraeffectsplugin/extraeffectsplugin.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | CONFIG += plugin 3 | HEADERS = ../textart/textartinterface.h \ 4 | extraeffectsplugin.h 5 | SOURCES = extraeffectsplugin.cpp 6 | DESTDIR = ../textart/plugins 7 | -------------------------------------------------------------------------------- /chap21/textart/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "textartdialog.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | TextArtDialog dialog(QObject::tr("Text Art")); 9 | dialog.resize(600, 300); 10 | dialog.show(); 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /chap21/textart/textart.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = textartdialog.h \ 3 | textartinterface.h 4 | SOURCES = main.cpp \ 5 | textartdialog.cpp 6 | -------------------------------------------------------------------------------- /chap21/textart/textartdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTARTDIALOG_H 2 | #define TEXTARTDIALOG_H 3 | 4 | #include 5 | #include 6 | 7 | class QDialogButtonBox; 8 | class QDir; 9 | class QListWidget; 10 | class TextArtInterface; 11 | 12 | class TextArtDialog : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | TextArtDialog(const QString &text, QWidget *parent = 0); 18 | 19 | QPixmap selectedPixmap() const; 20 | 21 | private: 22 | static QDir directoryOf(const QString &subdir); 23 | void loadPlugins(); 24 | void populateListWidget(const QString &text); 25 | 26 | QListWidget *listWidget; 27 | QDialogButtonBox *buttonBox; 28 | QList interfaces; 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /chap21/textart/textartinterface.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTARTINTERFACE_H 2 | #define TEXTARTINTERFACE_H 3 | 4 | class QBrush; 5 | class QFont; 6 | class QPen; 7 | class QPixmap; 8 | class QSize; 9 | class QString; 10 | class QStringList; 11 | 12 | class TextArtInterface 13 | { 14 | public: 15 | virtual ~TextArtInterface() { } 16 | 17 | virtual QStringList effects() const = 0; 18 | virtual QPixmap applyEffect(const QString &effect, 19 | const QString &text, 20 | const QFont &font, const QSize &size, 21 | const QPen &pen, 22 | const QBrush &brush) = 0; 23 | }; 24 | 25 | Q_DECLARE_INTERFACE(TextArtInterface, 26 | "com.software-inc.TextArt.TextArtInterface/1.0") 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /chap22/calculator/calculator.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += script 3 | HEADERS = calculator.h 4 | SOURCES = calculator.cpp \ 5 | main.cpp 6 | -------------------------------------------------------------------------------- /chap22/calculator/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "calculator.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | Calculator calc; 9 | calc.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap22/calculator/scripts/cube.js: -------------------------------------------------------------------------------- 1 | return x * x * x; 2 | -------------------------------------------------------------------------------- /chap22/calculator/scripts/factorial.js: -------------------------------------------------------------------------------- 1 | function factorial(n) 2 | { 3 | if (n <= 1) { 4 | return 1; 5 | } else { 6 | return n * factorial(n - 1); 7 | } 8 | } 9 | 10 | return factorial(Math.floor(x)); 11 | -------------------------------------------------------------------------------- /chap22/calculator/scripts/pi.js: -------------------------------------------------------------------------------- 1 | return 3.14159265358979323846; 2 | -------------------------------------------------------------------------------- /chap22/gaspump/filterdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef FILTERDIALOG_H 2 | #define FILTERDIALOG_H 3 | 4 | #include 5 | #include 6 | 7 | #include "ui_filterdialog.h" 8 | 9 | class PumpFilter; 10 | class PumpSpreadsheet; 11 | 12 | class FilterDialog : public QDialog, private Ui::FilterDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | FilterDialog(QWidget *parent = 0); 18 | 19 | void initFromSpreadsheet(PumpSpreadsheet *spreadsheet); 20 | PumpFilter filter() const; 21 | 22 | private: 23 | void populateComboBox(QComboBox *comboBox, 24 | const QSet &texts); 25 | QString comboBoxText(const QComboBox *comboBox) const; 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /chap22/gaspump/gaspump.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += script xml 3 | HEADERS = filterdialog.h \ 4 | pumpspreadsheet.h \ 5 | pumpwindow.h \ 6 | scripting.h 7 | SOURCES = filterdialog.cpp \ 8 | main.cpp \ 9 | pumpspreadsheet.cpp \ 10 | pumpwindow.cpp \ 11 | scripting.cpp 12 | FORMS = filterdialog.ui 13 | -------------------------------------------------------------------------------- /chap22/gaspump/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "pumpwindow.h" 5 | #include "scripting.h" 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QApplication app(argc, argv); 10 | QStringList args = QApplication::arguments(); 11 | if (args.count() >= 3 && args[1] == "-script") { 12 | runScript(args[2], args.mid(3)); 13 | return 0; 14 | } else if (args.count() == 1) { 15 | PumpWindow window; 16 | window.show(); 17 | window.resize(600, 400); 18 | return app.exec(); 19 | } else { 20 | std::cerr << "Usage: gaspump [-script myscript.js ]" 21 | << std::endl; 22 | return 1; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /chap22/gaspump/scripts/onlyok.js: -------------------------------------------------------------------------------- 1 | if (args.length == 0) 2 | throw Error("No files specified on the command line"); 3 | 4 | for (var i = 0; i < args.length; ++i) { 5 | spreadsheet.clearData(); 6 | if (!spreadsheet.addData(args[i], PumpSpreadsheet.Pump2000)) 7 | throw Error("Error loading Pump 2000 data"); 8 | 9 | var filter = new PumpFilter; 10 | filter.status = "OK"; 11 | 12 | spreadsheet.applyFilter(filter); 13 | if (!spreadsheet.saveData(args[i], PumpSpreadsheet.Pump2000)) 14 | throw Error("Error saving Pump 2000 data"); 15 | 16 | print("Removed erroneous transactions from " + args[i]); 17 | } 18 | -------------------------------------------------------------------------------- /chap22/gaspump/scripts/p20togpx.js: -------------------------------------------------------------------------------- 1 | if (args.length == 0) 2 | throw Error("No files specified on the command line"); 3 | 4 | for (var i = 0; i < args.length; ++i) { 5 | spreadsheet.clearData(); 6 | if (!spreadsheet.addData(args[i], PumpSpreadsheet.Pump2000)) 7 | throw Error("Error loading Pump 2000 data"); 8 | 9 | var outFileName = args[i]; 10 | if (outFileName.slice(-4) == ".p20") 11 | outFileName = outFileName.slice(0, -4); 12 | outFileName += ".gpx"; 13 | 14 | if (!spreadsheet.saveData(outFileName, PumpSpreadsheet.GasPumpXml)) 15 | throw Error("Error saving GasPumpXml data"); 16 | 17 | print("Created " + outFileName + " from " + args[i]); 18 | } 19 | -------------------------------------------------------------------------------- /chap22/gaspump/scripts/tohtml.js: -------------------------------------------------------------------------------- 1 | if (args.length == 0) 2 | throw Error("No files specified on the command line"); 3 | 4 | print(""); 5 | for (var i = 0; i < args.length; ++i) { 6 | spreadsheet.clearData(); 7 | if (!spreadsheet.addData(args[i], PumpSpreadsheet.Pump2000)) 8 | throw Error("Error loading Pump 2000 data"); 9 | 10 | print(""); 12 | for (var row = 0; row < spreadsheet.rowCount; ++row) { 13 | print(""); 14 | for (var column = 0; column < spreadsheet.columnCount; 15 | ++column) { 16 | print(""); 17 | } 18 | print(""); 19 | } 20 | } 21 | print("
" 11 | + args[i] + "
" + spreadsheet.text(row, column) + "
"); 22 | -------------------------------------------------------------------------------- /chap22/gaspump/scripts/toliters.js: -------------------------------------------------------------------------------- 1 | const LitersPerGallon = 3.785411784; 2 | 3 | if (args.length == 0) 4 | throw Error("No files specified on the command line"); 5 | 6 | for (var i = 0; i < args.length; ++i) { 7 | spreadsheet.clearData(); 8 | if (!spreadsheet.addData(args[i], PumpSpreadsheet.Pump2000)) 9 | throw Error("Error loading Pump 2000 data"); 10 | 11 | spreadsheet.convertUnits(LitersPerGallon); 12 | if (!spreadsheet.saveData(args[i], PumpSpreadsheet.Pump2000)) 13 | throw Error("Error saving Pump 2000 data"); 14 | 15 | print("Converted gallons to liters in " + args[i]); 16 | } 17 | -------------------------------------------------------------------------------- /chap22/htmleditor/htmleditor.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT += script 3 | CONFIG += uitools 4 | HEADERS = htmlsyntaxhighlighter.h \ 5 | htmlwindow.h 6 | SOURCES = htmlsyntaxhighlighter.cpp \ 7 | htmlwindow.cpp \ 8 | main.cpp 9 | -------------------------------------------------------------------------------- /chap22/htmleditor/htmlsyntaxhighlighter.h: -------------------------------------------------------------------------------- 1 | #ifndef HTMLSYNTAXHIGHLIGHTER_H 2 | #define HTMLSYNTAXHIGHLIGHTER_H 3 | 4 | #include 5 | 6 | class HtmlSyntaxHighlighter : public QSyntaxHighlighter 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | enum Construct { 12 | Entity, 13 | Tag, 14 | Comment, 15 | LastConstruct = Comment 16 | }; 17 | 18 | HtmlSyntaxHighlighter(QTextDocument *document); 19 | 20 | void setFormatFor(Construct construct, 21 | const QTextCharFormat &format); 22 | void setFormatFor(Construct construct, 23 | const QColor &color); 24 | void setFormatFor(Construct construct, 25 | const QFont &font); 26 | QTextCharFormat formatFor(Construct construct) const 27 | { return formats[construct]; } 28 | 29 | protected: 30 | enum State { 31 | NormalState = -1, 32 | InComment, 33 | InTag 34 | }; 35 | 36 | void highlightBlock(const QString &text); 37 | 38 | private: 39 | QTextCharFormat formats[LastConstruct + 1]; 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /chap22/htmleditor/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "htmlwindow.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | HtmlWindow window; 9 | window.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap22/htmleditor/scripts/statisticsdialog.js: -------------------------------------------------------------------------------- 1 | var obj = new Object; 2 | 3 | obj.text = "&Statistics..."; 4 | 5 | obj.run = function() { 6 | var text = this.textEdit.plainText; 7 | this.dialog.frame.charCountLineEdit.text = text.length; 8 | this.dialog.frame.wordCountLineEdit.text = this.wordCount(text); 9 | this.dialog.frame.lineCountLineEdit.text = this.lineCount(text); 10 | this.dialog.exec(); 11 | }; 12 | 13 | obj.wordCount = function(text) { 14 | var regExp = new RegExp("\\w+", "g"); 15 | var count = 0; 16 | while (regExp.exec(text)) 17 | ++count; 18 | return count; 19 | }; 20 | 21 | obj.lineCount = function(text) { 22 | var count = 0; 23 | var pos = 0; 24 | while ((pos = text.indexOf("\n", pos)) != -1) { 25 | ++count; 26 | ++pos; 27 | } 28 | return count + 1; 29 | }; 30 | 31 | return obj; 32 | -------------------------------------------------------------------------------- /chap23/addressbook/abitem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "abitem.h" 4 | 5 | ABItem::ABItem(QTreeWidget *treeWidget) 6 | : QTreeWidgetItem(treeWidget) 7 | { 8 | } 9 | 10 | void ABItem::setContact(const QString &contact) 11 | { 12 | setText(0, contact); 13 | } 14 | 15 | void ABItem::setAddress(const QString &address) 16 | { 17 | QString str = address; 18 | str.replace("\r\n", ", "); 19 | setText(1, str); 20 | } 21 | 22 | void ABItem::setPhoneNumber(const QString &number) 23 | { 24 | setText(2, number); 25 | } 26 | 27 | void ABItem::remove() 28 | { 29 | delete this; 30 | } 31 | -------------------------------------------------------------------------------- /chap23/addressbook/abitem.h: -------------------------------------------------------------------------------- 1 | #ifndef ABITEM_H 2 | #define ABITEM_H 3 | 4 | #include 5 | #include 6 | 7 | class ABItem : public QObject, public QTreeWidgetItem 8 | { 9 | Q_OBJECT 10 | Q_PROPERTY(QString contact READ contact WRITE setContact) 11 | Q_PROPERTY(QString address READ address WRITE setAddress) 12 | Q_PROPERTY(QString phoneNumber READ phoneNumber 13 | WRITE setPhoneNumber) 14 | Q_CLASSINFO("ClassID", "{bc82730e-5f39-4e5c-96be-461c2cd0d282}") 15 | Q_CLASSINFO("InterfaceID", "{c8bc1656-870e-48a9-9937-fbe1ceff8b2e}") 16 | Q_CLASSINFO("ToSuperClass", "ABItem") 17 | 18 | public: 19 | ABItem(QTreeWidget *treeWidget); 20 | 21 | void setContact(const QString &contact); 22 | QString contact() const { return text(0); } 23 | void setAddress(const QString &address); 24 | QString address() const { return text(1); } 25 | void setPhoneNumber(const QString &number); 26 | QString phoneNumber() const { return text(2); } 27 | 28 | public slots: 29 | void remove(); 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /chap23/addressbook/addressbook.h: -------------------------------------------------------------------------------- 1 | #ifndef ADDRESSBOOK_H 2 | #define ADDRESSBOOK_H 3 | 4 | #include 5 | 6 | #include "abitem.h" 7 | 8 | class AddressBook : public QMainWindow 9 | { 10 | Q_OBJECT 11 | Q_PROPERTY(int count READ count) 12 | Q_CLASSINFO("ClassID", "{588141ef-110d-4beb-95ab-ee6a478b576d}") 13 | Q_CLASSINFO("InterfaceID", "{718780ec-b30c-4d88-83b3-79b3d9e78502}") 14 | Q_CLASSINFO("ToSuperClass", "AddressBook") 15 | 16 | public: 17 | AddressBook(QWidget *parent = 0); 18 | ~AddressBook(); 19 | 20 | int count() const; 21 | 22 | public slots: 23 | ABItem *createEntry(const QString &contact); 24 | ABItem *findEntry(const QString &contact) const; 25 | ABItem *entryAt(int index) const; 26 | 27 | private slots: 28 | void addEntry(); 29 | void editEntry(); 30 | void deleteEntry(); 31 | 32 | private: 33 | void createActions(); 34 | void createMenus(); 35 | 36 | QTreeWidget *treeWidget; 37 | QMenu *fileMenu; 38 | QMenu *editMenu; 39 | QAction *exitAction; 40 | QAction *addEntryAction; 41 | QAction *editEntryAction; 42 | QAction *deleteEntryAction; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /chap23/addressbook/addressbook.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += qaxserver 3 | HEADERS = abitem.h \ 4 | addressbook.h \ 5 | editdialog.h 6 | SOURCES = abitem.cpp \ 7 | addressbook.cpp \ 8 | editdialog.cpp \ 9 | main.cpp 10 | FORMS = editdialog.ui 11 | RC_FILE = qaxserver.rc 12 | -------------------------------------------------------------------------------- /chap23/addressbook/editdialog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "abitem.h" 4 | #include "editdialog.h" 5 | 6 | EditDialog::EditDialog(QTreeWidget *treeWidget, QWidget *parent) 7 | : QDialog(parent) 8 | { 9 | setupUi(this); 10 | 11 | this->treeWidget = treeWidget; 12 | currentItem = 0; 13 | 14 | setWindowTitle(tr("Add Entry")); 15 | } 16 | 17 | EditDialog::EditDialog(ABItem *item, QWidget *parent) 18 | : QDialog(parent) 19 | { 20 | setupUi(this); 21 | 22 | contactLineEdit->setText(item->contact()); 23 | addressLineEdit->setText(item->address()); 24 | phoneLineEdit->setText(item->phoneNumber()); 25 | treeWidget = item->treeWidget(); 26 | currentItem = item; 27 | 28 | setWindowTitle(tr("Edit Entry")); 29 | } 30 | 31 | void EditDialog::accept() 32 | { 33 | if (!currentItem) 34 | currentItem = new ABItem(treeWidget); 35 | currentItem->setContact(contactLineEdit->text()); 36 | currentItem->setAddress(addressLineEdit->text()); 37 | currentItem->setPhoneNumber(phoneLineEdit->text()); 38 | 39 | QDialog::accept(); 40 | } 41 | -------------------------------------------------------------------------------- /chap23/addressbook/editdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef EDITDIALOG_H 2 | #define EDITDILAOG_H 3 | 4 | #include 5 | 6 | #include "ui_editdialog.h" 7 | 8 | class QTreeWidget; 9 | class ABItem; 10 | 11 | class EditDialog : public QDialog, private Ui::EditDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | EditDialog(QTreeWidget *treeWidget, QWidget *parent = 0); 17 | EditDialog(ABItem *item, QWidget *parent = 0); 18 | 19 | void accept(); 20 | 21 | private: 22 | QTreeWidget *treeWidget; 23 | ABItem *currentItem; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /chap23/addressbook/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "addressbook.h" 5 | 6 | QAXFACTORY_BEGIN("{2b2b6f3e-86cf-4c49-9df5-80483b47f17b}", 7 | "{8e827b25-148b-4307-ba7d-23f275244818}") 8 | QAXCLASS(AddressBook) 9 | QAXTYPE(ABItem) 10 | QAXFACTORY_END() 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | QApplication app(argc, argv); 15 | if (!QAxFactory::isServer()) { 16 | AddressBook addressBook; 17 | addressBook.show(); 18 | return app.exec(); 19 | } 20 | return app.exec(); 21 | } 22 | -------------------------------------------------------------------------------- /chap23/addressbook/qaxserver.rc: -------------------------------------------------------------------------------- 1 | 1 TYPELIB "addressbook.pro" 2 | -------------------------------------------------------------------------------- /chap23/addressbook/vb/AddressBook.vbp: -------------------------------------------------------------------------------- 1 | Type=Exe 2 | Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\WINNT\System32\stdole2.tlb#OLE Automation 3 | Reference=*\G{00025E01-0000-0000-C000-000000000046}#5.0#0#..\..\..\..\..\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll#Microsoft DAO 3.6 Object Library 4 | Reference=*\G{2B2B6F3E-86CF-4C49-9DF5-80483B47F17B}#1.0#0#..\Debug\qaxaddressbook.exe#qaxaddressbook 1.0 Type Library 5 | Form=AddressList.frm 6 | Form=EditDialog.frm 7 | Startup="AddressView" 8 | Command32="" 9 | Name="AddressManager" 10 | HelpContextID="0" 11 | CompatibleMode="0" 12 | MajorVer=1 13 | MinorVer=0 14 | RevisionVer=0 15 | AutoIncrementVer=0 16 | ServerSupportFiles=0 17 | VersionCompanyName="Trolltech AS" 18 | CompilationType=0 19 | OptimizationType=0 20 | FavorPentiumPro(tm)=0 21 | CodeViewDebugInfo=0 22 | NoAliasing=0 23 | BoundsCheck=0 24 | OverflowCheck=0 25 | FlPointCheck=0 26 | FDIVCheck=0 27 | UnroundedFP=0 28 | StartMode=0 29 | Unattended=0 30 | Retained=0 31 | ThreadPerObject=0 32 | MaxNumberOfThreads=1 33 | DebugStartupOption=0 34 | 35 | [MS Transaction Server] 36 | AutoRefresh=1 37 | -------------------------------------------------------------------------------- /chap23/addressbook/vb/AddressBook.vbw: -------------------------------------------------------------------------------- 1 | AddressView = 109, 36, 1036, 786, , 206, -2, 793, 443, C 2 | EditDialog = 273, 258, 1242, 977, C, 811, 47, 1273, 346, C 3 | -------------------------------------------------------------------------------- /chap23/bouncer/axbouncer.h: -------------------------------------------------------------------------------- 1 | #ifndef AXBOUNCER_H 2 | #define AXBOUNCER_H 3 | 4 | #include 5 | #include 6 | 7 | class AxBouncer : public QWidget, public QAxBindable 8 | { 9 | Q_OBJECT 10 | Q_ENUMS(SpeedValue) 11 | Q_PROPERTY(QColor color READ color WRITE setColor) 12 | Q_PROPERTY(SpeedValue speed READ speed WRITE setSpeed) 13 | Q_PROPERTY(int radius READ radius WRITE setRadius) 14 | Q_PROPERTY(bool running READ isRunning) 15 | 16 | public: 17 | enum SpeedValue { Slow, Normal, Fast }; 18 | 19 | AxBouncer(QWidget *parent = 0); 20 | 21 | void setSpeed(SpeedValue newSpeed); 22 | SpeedValue speed() const { return ballSpeed; } 23 | void setRadius(int newRadius); 24 | int radius() const { return ballRadius; } 25 | void setColor(const QColor &newColor); 26 | QColor color() const { return ballColor; } 27 | bool isRunning() const { return myTimerId != 0; } 28 | QSize sizeHint() const; 29 | QAxAggregated *createAggregate(); 30 | 31 | public slots: 32 | void start(); 33 | void stop(); 34 | 35 | signals: 36 | void bouncing(); 37 | 38 | protected: 39 | void paintEvent(QPaintEvent *event); 40 | void timerEvent(QTimerEvent *event); 41 | 42 | private: 43 | int intervalInMilliseconds() const; 44 | 45 | QColor ballColor; 46 | SpeedValue ballSpeed; 47 | int ballRadius; 48 | int myTimerId; 49 | int x; 50 | int delta; 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /chap23/bouncer/bouncer.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | CONFIG += dll qaxserver 3 | HEADERS = axbouncer.h \ 4 | objectsafetyimpl.h 5 | SOURCES = axbouncer.cpp \ 6 | main.cpp \ 7 | objectsafetyimpl.cpp 8 | RC_FILE = qaxserver.rc 9 | DEF_FILE = qaxserver.def 10 | -------------------------------------------------------------------------------- /chap23/bouncer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "axbouncer.h" 4 | 5 | QAXFACTORY_DEFAULT(AxBouncer, 6 | "{5e2461aa-a3e8-4f7a-8b04-307459a4c08c}", 7 | "{533af11f-4899-43de-8b7f-2ddf588d1015}", 8 | "{772c14a5-a840-4023-b79d-19549ece0cd9}", 9 | "{dbce1e56-70dd-4f74-85e0-95c65d86254d}", 10 | "{3f3db5e0-78ff-4e35-8a5d-3d3b96c83e09}") 11 | -------------------------------------------------------------------------------- /chap23/bouncer/objectsafetyimpl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "objectsafetyimpl.h" 4 | 5 | long ObjectSafetyImpl::queryInterface(const QUuid &iid, void **iface) 6 | { 7 | *iface = 0; 8 | if (iid == IID_IObjectSafety) { 9 | *iface = static_cast(this); 10 | } else { 11 | return E_NOINTERFACE; 12 | } 13 | AddRef(); 14 | return S_OK; 15 | } 16 | 17 | HRESULT WINAPI ObjectSafetyImpl::GetInterfaceSafetyOptions( 18 | REFIID /* riid */, DWORD *pdwSupportedOptions, 19 | DWORD *pdwEnabledOptions) 20 | { 21 | *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA 22 | | INTERFACESAFE_FOR_UNTRUSTED_CALLER; 23 | *pdwEnabledOptions = *pdwSupportedOptions; 24 | return S_OK; 25 | } 26 | 27 | HRESULT WINAPI ObjectSafetyImpl::SetInterfaceSafetyOptions( 28 | REFIID /* riid */, DWORD /* pdwSupportedOptions */, 29 | DWORD /* pdwEnabledOptions */) 30 | { 31 | return S_OK; 32 | } 33 | -------------------------------------------------------------------------------- /chap23/bouncer/objectsafetyimpl.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTSAFETYIMPL_H 2 | #define OBJECTSAFETYIMPL_H 3 | 4 | #include 5 | #include 6 | 7 | class ObjectSafetyImpl : public QAxAggregated, public IObjectSafety 8 | { 9 | public: 10 | long queryInterface(const QUuid &iid, void **iface); 11 | 12 | QAXAGG_IUNKNOWN 13 | 14 | HRESULT WINAPI GetInterfaceSafetyOptions(REFIID riid, 15 | DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions); 16 | HRESULT WINAPI SetInterfaceSafetyOptions(REFIID riid, 17 | DWORD pdwSupportedOptions, DWORD pdwEnabledOptions); 18 | }; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /chap23/bouncer/qaxserver.def: -------------------------------------------------------------------------------- 1 | ; mfc_test.def : Declares the module parameters. 2 | 3 | EXPORTS 4 | DllCanUnloadNow PRIVATE 5 | DllGetClassObject PRIVATE 6 | DllRegisterServer PRIVATE 7 | DllUnregisterServer PRIVATE 8 | DumpIDL PRIVATE 9 | -------------------------------------------------------------------------------- /chap23/bouncer/qaxserver.rc: -------------------------------------------------------------------------------- 1 | 1 TYPELIB "bouncer.pro" 2 | -------------------------------------------------------------------------------- /chap23/mediaplayer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "playerwindow.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | PlayerWindow playerWin; 9 | playerWin.show(); 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /chap23/mediaplayer/mediaplayer.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += qaxcontainer 3 | HEADERS = playerwindow.h 4 | SOURCES = main.cpp \ 5 | playerwindow.cpp 6 | -------------------------------------------------------------------------------- /chap23/mediaplayer/playerwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef PLAYERWINDOW_H 2 | #define PLAYERWINDOW_H 3 | 4 | #include 5 | 6 | class QAxWidget; 7 | class QSlider; 8 | class QToolButton; 9 | 10 | class PlayerWindow : public QWidget 11 | { 12 | Q_OBJECT 13 | Q_ENUMS(ReadyStateConstants) 14 | 15 | public: 16 | enum PlayStateConstants { Stopped = 0, Paused = 1, Playing = 2 }; 17 | enum ReadyStateConstants { Uninitialized = 0, Loading = 1, 18 | Interactive = 3, Complete = 4 }; 19 | 20 | PlayerWindow(); 21 | 22 | protected: 23 | void timerEvent(QTimerEvent *event); 24 | 25 | private slots: 26 | void onPlayStateChange(int oldState, int newState); 27 | void onReadyStateChange(ReadyStateConstants readyState); 28 | void onPositionChange(double oldPos, double newPos); 29 | void sliderValueChanged(int newValue); 30 | void openFile(); 31 | 32 | private: 33 | QAxWidget *wmp; 34 | QToolButton *openButton; 35 | QToolButton *playPauseButton; 36 | QToolButton *stopButton; 37 | QSlider *seekSlider; 38 | QString fileFilters; 39 | int updateTimer; 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /chap23/tictactoe/application.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "application.h" 4 | #include "tictactoe.h" 5 | 6 | Application::Application(int &argc, char *argv[]) 7 | : QApplication(argc, argv) 8 | { 9 | ticTacToe = 0; 10 | } 11 | 12 | void Application::setTicTacToe(TicTacToe *toe) 13 | { 14 | ticTacToe = toe; 15 | } 16 | 17 | void Application::saveState(QSessionManager &sessionManager) 18 | { 19 | QString fileName = ticTacToe->saveState(); 20 | 21 | QStringList discardCommand; 22 | discardCommand << "rm" << fileName; 23 | sessionManager.setDiscardCommand(discardCommand); 24 | } 25 | 26 | void Application::commitData(QSessionManager &sessionManager) 27 | { 28 | if (ticTacToe->gameInProgress() 29 | && sessionManager.allowsInteraction()) { 30 | int r = QMessageBox::warning(ticTacToe, tr("Tic-Tac-Toe"), 31 | tr("The game hasn't finished.\n" 32 | "Do you really want to quit?"), 33 | QMessageBox::Yes | QMessageBox::No); 34 | if (r == QMessageBox::Yes) { 35 | sessionManager.release(); 36 | } else { 37 | sessionManager.cancel(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /chap23/tictactoe/application.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLICATION_H 2 | #define APPLICATION_H 3 | 4 | #include 5 | 6 | class TicTacToe; 7 | 8 | class Application : public QApplication 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | Application(int &argc, char *argv[]); 14 | 15 | void setTicTacToe(TicTacToe *toe); 16 | void saveState(QSessionManager &sessionManager); 17 | void commitData(QSessionManager &sessionManager); 18 | 19 | private: 20 | TicTacToe *ticTacToe; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /chap23/tictactoe/main.cpp: -------------------------------------------------------------------------------- 1 | #include "application.h" 2 | #include "tictactoe.h" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | Application app(argc, argv); 7 | TicTacToe toe; 8 | toe.setObjectName("toe"); 9 | app.setTicTacToe(&toe); 10 | toe.show(); 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /chap23/tictactoe/tictactoe.h: -------------------------------------------------------------------------------- 1 | #ifndef TICTACTOE_H 2 | #define TICTACTOE_H 3 | 4 | #include 5 | 6 | class TicTacToe : public QWidget 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | TicTacToe(QWidget *parent = 0); 12 | 13 | bool gameInProgress() const; 14 | QString saveState() const; 15 | QSize sizeHint() const; 16 | 17 | protected: 18 | void paintEvent(QPaintEvent *event); 19 | void mousePressEvent(QMouseEvent *event); 20 | 21 | private: 22 | enum { Empty = '-', Cross = 'X', Nought = 'O' }; 23 | 24 | void clearBoard(); 25 | void restoreState(); 26 | QString sessionFileName() const; 27 | QRect cellRect(int row, int column) const; 28 | int cellWidth() const { return width() / 3; } 29 | int cellHeight() const { return height() / 3; } 30 | bool threeInARow(int row1, int col1, int row3, int col3) const; 31 | 32 | char board[3][3]; 33 | int turnNumber; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /chap23/tictactoe/tictactoe.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | HEADERS = application.h \ 3 | tictactoe.h 4 | SOURCES = application.cpp \ 5 | main.cpp \ 6 | tictactoe.cpp 7 | -------------------------------------------------------------------------------- /chap24/expenses/expense.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "expense.h" 4 | 5 | Expense::Expense() 6 | { 7 | myAmount = 0.0; 8 | } 9 | 10 | Expense::Expense(const QDate &date, const QString &desc, qreal amount) 11 | { 12 | myDate = date; 13 | myDesc = desc; 14 | myAmount = amount; 15 | } 16 | 17 | bool Expense::isNull() const 18 | { 19 | return myDate.isNull(); 20 | } 21 | 22 | void Expense::setDate(const QDate &date) 23 | { 24 | myDate = date; 25 | } 26 | 27 | QDate Expense::date() const 28 | { 29 | return myDate; 30 | } 31 | 32 | void Expense::setDescription(const QString &desc) 33 | { 34 | myDesc = desc; 35 | } 36 | 37 | QString Expense::description() const 38 | { 39 | return myDesc; 40 | } 41 | 42 | void Expense::setAmount(qreal amount) 43 | { 44 | myAmount = amount; 45 | } 46 | 47 | qreal Expense::amount() const 48 | { 49 | return myAmount; 50 | } 51 | -------------------------------------------------------------------------------- /chap24/expenses/expense.h: -------------------------------------------------------------------------------- 1 | #ifndef EXPENSE_H 2 | #define EXPENSE_H 3 | 4 | #include 5 | #include 6 | 7 | class Expense 8 | { 9 | public: 10 | Expense(); 11 | Expense(const QDate &date, const QString &desc, qreal amount); 12 | 13 | bool isNull() const; 14 | void setDate(const QDate &date); 15 | QDate date() const; 16 | void setDescription(const QString &desc); 17 | QString description() const; 18 | void setAmount(qreal amount); 19 | qreal amount() const; 20 | 21 | private: 22 | QDate myDate; 23 | QString myDesc; 24 | qreal myAmount; 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /chap24/expenses/expensedialog.h: -------------------------------------------------------------------------------- 1 | #ifndef EXPENSEDIALOG_H 2 | #define EXPENSEDIALOG_H 3 | 4 | #include 5 | 6 | #include "expense.h" 7 | 8 | class QAction; 9 | class QComboBox; 10 | class QDateEdit; 11 | class QDoubleSpinBox; 12 | class QLabel; 13 | 14 | class ExpenseDialog : public QDialog 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | ExpenseDialog(const Expense &expense, QWidget *parent = 0); 20 | 21 | Expense expense() const { return currentExpense; } 22 | 23 | public slots: 24 | void accept(); 25 | 26 | private: 27 | void createActions(); 28 | void createMenuOrToolBar(); 29 | 30 | Expense currentExpense; 31 | 32 | QLabel *dateLabel; 33 | QLabel *descLabel; 34 | QLabel *amountLabel; 35 | QDateEdit *dateEdit; 36 | QComboBox *descComboBox; 37 | QDoubleSpinBox *amountSpinBox; 38 | QAction *okAction; 39 | QAction *cancelAction; 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /chap24/expenses/expenses.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Comment[]=A program to record and SMS expenses 3 | Exec=expenses 4 | Icon=expenses/expenses 5 | Type=Application 6 | Name[]=Expenses 7 | -------------------------------------------------------------------------------- /chap24/expenses/expenses.pro: -------------------------------------------------------------------------------- 1 | qtopia_project(qtopia app) 2 | depends(libraries/qtopiapim) 3 | 4 | CONFIG += qtopia_main no_quicklaunch 5 | HEADERS += expense.h \ 6 | expensedialog.h \ 7 | expensewindow.h 8 | SOURCES += expense.cpp \ 9 | expensedialog.cpp \ 10 | expensewindow.cpp \ 11 | main.cpp 12 | INSTALLS += desktop pics 13 | 14 | desktop.files = expenses.desktop 15 | desktop.path = /apps/Applications 16 | desktop.hint = desktop 17 | 18 | pics.files = pics/* 19 | pics.path = /pics/expenses 20 | pics.hint = pics 21 | 22 | pkg.name = expenses 23 | pkg.desc = A program to record and SMS expenses 24 | pkg.version = 1.0.0 25 | pkg.domain = window 26 | -------------------------------------------------------------------------------- /chap24/expenses/expensewindow.h: -------------------------------------------------------------------------------- 1 | #ifndef EXPENSEWINDOW_H 2 | #define EXPENSEWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | #include "expense.h" 8 | 9 | class QAction; 10 | class QLabel; 11 | class QListWidget; 12 | 13 | class ExpenseWindow : public QMainWindow 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | ExpenseWindow(QWidget *parent = 0, Qt::WFlags flags = 0); 19 | 20 | protected: 21 | void closeEvent(QCloseEvent *event); 22 | 23 | private slots: 24 | void add(); 25 | void edit(); 26 | void del(); 27 | void send(); 28 | void clear(); 29 | 30 | private: 31 | void createActions(); 32 | void createMenuOrToolBar(); 33 | void loadData(); 34 | void showData(); 35 | 36 | QWidget *centralWidget; 37 | QListWidget *listWidget; 38 | QLabel *totalLabel; 39 | QLabel *totalAmountLabel; 40 | QAction *addAction; 41 | QAction *editAction; 42 | QAction *deleteAction; 43 | QAction *sendAction; 44 | QAction *clearAction; 45 | 46 | QList expenses; 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /chap24/expenses/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "expensewindow.h" 4 | 5 | QTOPIA_ADD_APPLICATION("Expenses", ExpenseWindow) 6 | QTOPIA_MAIN 7 | -------------------------------------------------------------------------------- /chap24/expenses/pics/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap24/expenses/pics/add.png -------------------------------------------------------------------------------- /chap24/expenses/pics/cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap24/expenses/pics/cancel.png -------------------------------------------------------------------------------- /chap24/expenses/pics/clear.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap24/expenses/pics/clear.png -------------------------------------------------------------------------------- /chap24/expenses/pics/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap24/expenses/pics/delete.png -------------------------------------------------------------------------------- /chap24/expenses/pics/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap24/expenses/pics/edit.png -------------------------------------------------------------------------------- /chap24/expenses/pics/expenses.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap24/expenses/pics/expenses.png -------------------------------------------------------------------------------- /chap24/expenses/pics/ok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap24/expenses/pics/ok.png -------------------------------------------------------------------------------- /chap24/expenses/pics/send.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap24/expenses/pics/send.png -------------------------------------------------------------------------------- /chap24/unitconverter/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "unitconverter.h" 4 | 5 | QTOPIA_ADD_APPLICATION("UnitConverter", UnitConverter) 6 | QTOPIA_MAIN 7 | -------------------------------------------------------------------------------- /chap24/unitconverter/pics/Example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cggos/CPPGUIProgrammingWithQt4/c149d26cc6c86e06100602b17298640332c5dc1a/chap24/unitconverter/pics/Example.png -------------------------------------------------------------------------------- /chap24/unitconverter/unitconverter.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Comment[]=A program to convert between various units of measurement 3 | Exec=unitconverter 4 | Icon=unitconverter/Example 5 | Type=Application 6 | Name[]=Unit Converter 7 | -------------------------------------------------------------------------------- /chap24/unitconverter/unitconverter.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITCONVERTER_H 2 | #define UNITCONVERTER_H 3 | 4 | #include 5 | #include 6 | 7 | class QComboBox; 8 | class QDoubleSpinBox; 9 | class QLabel; 10 | 11 | class UnitConverter : public QMainWindow 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | UnitConverter(QWidget *parent = 0, Qt::WFlags flags = 0); 17 | 18 | private slots: 19 | void calculate(); 20 | void updateToComboBox(); 21 | 22 | private: 23 | QMap unitsOfLength; 24 | QMap unitsOfWeight; 25 | 26 | QWidget *centralWidget; 27 | QLabel *titleLabel; 28 | QLabel *isTheEquivalentOfLabel; 29 | QDoubleSpinBox *fromAmountSpinBox; 30 | QLabel *toAmountLabel; 31 | QComboBox *fromUnitComboBox; 32 | QComboBox *toUnitComboBox; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /chap24/unitconverter/unitconverter.pro: -------------------------------------------------------------------------------- 1 | qtopia_project(qtopia app) 2 | 3 | TARGET = unitconverter 4 | CONFIG += qtopia_main no_quicklaunch 5 | HEADERS += unitconverter.h 6 | SOURCES += main.cpp \ 7 | unitconverter.cpp 8 | INSTALLS += desktop pics 9 | 10 | desktop.files = unitconverter.desktop 11 | desktop.path = /apps/Applications 12 | desktop.hint = desktop 13 | 14 | pics.files = pics/* 15 | pics.path = /pics/unitconverter 16 | pics.hint = pics 17 | 18 | pkg.name = unitconverter 19 | pkg.desc = A program to convert between various units of measurement 20 | pkg.version = 1.0.0 21 | pkg.domain = window 22 | --------------------------------------------------------------------------------