mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add example main window in C++ and Qt that links against gnucash-engine.
The example was based on Qt4's "application" example, but the main window layout is done through the .ui file already. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18776 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
b041e5dddf
commit
cfd3a5b33e
@ -61,10 +61,11 @@ FIND_PROGRAM (GUILE_EXECUTABLE guile)
|
||||
|
||||
# ############################################################
|
||||
|
||||
#SET (QT_MIN_VERSION "4.5.0") # We need at least 4.5.0 (because only this is LGPL)
|
||||
#FIND_PACKAGE (Qt4 REQUIRED) # find and setup Qt4 for this project
|
||||
#INCLUDE_DIRECTORIES (${QT_INCLUDES})
|
||||
# Qt
|
||||
SET (QT_MIN_VERSION "4.5.0")
|
||||
FIND_PACKAGE (Qt4 REQUIRED) # find and setup Qt4 for this project
|
||||
|
||||
# Compiler flags
|
||||
IF (UNIX)
|
||||
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wdeclaration-after-statement -Wno-pointer-sign -D_FORTIFY_SOURCE=2 -Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wno-unused")
|
||||
ENDIF (UNIX)
|
||||
@ -210,4 +211,6 @@ ADD_SUBDIRECTORY (gnc-module)
|
||||
ADD_SUBDIRECTORY (engine)
|
||||
ADD_SUBDIRECTORY (backend/xml)
|
||||
|
||||
ADD_SUBDIRECTORY (gnc)
|
||||
|
||||
ADD_SUBDIRECTORY (test-core)
|
||||
|
73
src/gnc/CMakeLists.txt
Normal file
73
src/gnc/CMakeLists.txt
Normal file
@ -0,0 +1,73 @@
|
||||
# CMakeLists.txt for src/gnc
|
||||
|
||||
|
||||
# A test executable
|
||||
LINK_DIRECTORIES (${GLIB2_LIBRARY_DIRS}
|
||||
${GMODULE_LIBRARY_DIRS}
|
||||
${GOBJECT_LIBRARY_DIRS}
|
||||
${GTHREAD_LIBRARY_DIRS}
|
||||
${GCONF2_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
SET (gnc_SOURCES
|
||||
main.cpp
|
||||
mainwindow.cpp
|
||||
)
|
||||
|
||||
SET (gnc_QOBJECT_HEADERS
|
||||
mainwindow.hpp
|
||||
)
|
||||
SET (gnc_HEADERS ${gnc_QOBJECT_HEADERS}
|
||||
)
|
||||
|
||||
SET (gnc_FORMS
|
||||
mainwindow.ui
|
||||
)
|
||||
|
||||
SET (gnc_RESOURCES
|
||||
gnc.qrc
|
||||
)
|
||||
# Generation of resource files
|
||||
QT4_ADD_RESOURCES (gnc_RESOURCE ${gnc_RESOURCES})
|
||||
|
||||
# Generation of the foo_MOC_SRCS = moc_Class1.cxx moc_Class2.cxx
|
||||
QT4_WRAP_CPP (gnc_MOC_SOURCES ${gnc_QOBJECT_HEADERS})
|
||||
|
||||
# Generation of the ui source files
|
||||
QT4_WRAP_UI (gnc_FORMS_HEADERS ${gnc_FORMS})
|
||||
|
||||
INCLUDE_DIRECTORIES (${GLIB2_INCLUDE_DIRS})
|
||||
INCLUDE_DIRECTORIES (${LIBINTL_INCLUDE_PATH})
|
||||
INCLUDE_DIRECTORIES (${REGEX_INCLUDE_PATH})
|
||||
INCLUDE_DIRECTORIES (${LIBGUILE_INCLUDE_PATH})
|
||||
INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR} ) # for config.h
|
||||
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}) # for gnc-ui.h
|
||||
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/libqof/qof) # for qof.h
|
||||
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/gnc-module) # for gnc-glib-utils.h
|
||||
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/core-utils) # for gnc-glib-utils.h
|
||||
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/engine) # for gnc-glib-utils.h
|
||||
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/backend/xml)
|
||||
INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR}/engine) # for swig-runtime.h
|
||||
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR}) # for ui_mainwindow.h
|
||||
|
||||
INCLUDE_DIRECTORIES (${QT_INCLUDES})
|
||||
|
||||
ADD_EXECUTABLE (cpp-main
|
||||
${gnc_FORMS_HEADERS}
|
||||
${gnc_HEADERS}
|
||||
${gnc_MOC_SOURCES}
|
||||
${gnc_RESOURCE}
|
||||
${gnc_SOURCES}
|
||||
)
|
||||
|
||||
TARGET_LINK_LIBRARIES (cpp-main gnc-backend-xml engine gnc-module core-utils qof)
|
||||
TARGET_LINK_LIBRARIES (cpp-main ${GCONF2_LIBRARIES})
|
||||
TARGET_LINK_LIBRARIES (cpp-main ${GTHREAD_LIBRARIES} ${GOBJECT_LIBRARIES} ${GMODULE_LIBRARIES} ${GLIB2_LIBRARIES})
|
||||
TARGET_LINK_LIBRARIES (cpp-main ${LIBGUILE_LIBRARIES})
|
||||
TARGET_LINK_LIBRARIES (cpp-main ${LIBXML2_LIBRARIES})
|
||||
TARGET_LINK_LIBRARIES (cpp-main ${ZLIB_LIBRARIES})
|
||||
IF (WIN32)
|
||||
TARGET_LINK_LIBRARIES (cpp-main ${LIBINTL_LIBRARY} ${REGEX_LIBRARY})
|
||||
ENDIF (WIN32)
|
||||
|
||||
TARGET_LINK_LIBRARIES (cpp-main ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
|
20
src/gnc/bla.html
Normal file
20
src/gnc/bla.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
|
||||
<title>GnuCash C++ Test</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>GnuCash C++ Test</h1>
|
||||
|
||||
<p>This is a text that demonstrates how we can build a GnuCash variant in C++ and Qt.</p>
|
||||
|
||||
<h2>Images</h2>
|
||||
<p><img src=":/pixmaps/gnucash_splash.png"></p>
|
||||
<p>We can also embed images here in this compiled-in HTML page.</p>
|
||||
|
||||
<hr>
|
||||
<address></address>
|
||||
<!-- hhmts start -->Last modified: Mon Mar 1 09:11:12 CET 2010 <!-- hhmts end -->
|
||||
</body> </html>
|
23
src/gnc/gnc.qrc
Normal file
23
src/gnc/gnc.qrc
Normal file
@ -0,0 +1,23 @@
|
||||
<!DOCTYPE RCC>
|
||||
<RCC version="1.0">
|
||||
<qresource>
|
||||
<file>../pixmaps/gnc-account-delete.png</file>
|
||||
<file>../pixmaps/gnc-account-edit.png</file>
|
||||
<file>../pixmaps/gnc-account-new.png</file>
|
||||
<file>../pixmaps/gnc-account-open.png</file>
|
||||
<file>../pixmaps/gnc-account.png</file>
|
||||
<file>../pixmaps/gnc-invoice-edit.png</file>
|
||||
<file>../pixmaps/gnc-invoice.png</file>
|
||||
<file>../pixmaps/gnc-invoice-post.png</file>
|
||||
<file>../pixmaps/gnc-invoice-unpost.png</file>
|
||||
<file>../pixmaps/gnc-jumpto.png</file>
|
||||
<file>../pixmaps/gnc-split-trans.png</file>
|
||||
<file>../pixmaps/gnc-sx-new.png</file>
|
||||
<file>../pixmaps/gnc-transfer.png</file>
|
||||
<file>../pixmaps/gnucash-icon-16x16.png</file>
|
||||
<file>../pixmaps/gnucash-icon-32x32.png</file>
|
||||
<file>../pixmaps/gnucash-icon-48x48.png</file>
|
||||
<file>../pixmaps/gnucash_splash.png</file>
|
||||
<file>bla.html</file>
|
||||
</qresource>
|
||||
</RCC>
|
182
src/gnc/main.cpp
Normal file
182
src/gnc/main.cpp
Normal file
@ -0,0 +1,182 @@
|
||||
/*
|
||||
* gnucash-bin.c -- The program entry point for GnuCash
|
||||
*
|
||||
* Copyright (C) 2006 Chris Shoemaker <c.shoemaker@cox.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, contact:
|
||||
*
|
||||
* Free Software Foundation Voice: +1-617-542-5942
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libguile.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib.h>
|
||||
#include "gnc-module/gnc-module.h"
|
||||
#include "engine/gnc-path.h"
|
||||
#include "engine/binreloc.h"
|
||||
/* #include "gnc-version.h" */
|
||||
#include "engine/gnc-engine.h"
|
||||
#include "engine/gnc-filepath-utils.h"
|
||||
#include "engine/gnc-hooks.h"
|
||||
#include "engine/gnc-commodity.h"
|
||||
#include "core-utils/gnc-main.h"
|
||||
#include "engine/gnc-session.h"
|
||||
#include "engine/engine-helpers.h"
|
||||
#include "swig-runtime.h"
|
||||
|
||||
#include "gnc-backend-xml.h"
|
||||
|
||||
#ifdef HAVE_GETTEXT
|
||||
# include <libintl.h>
|
||||
# include <locale.h>
|
||||
#endif
|
||||
} // END extern C
|
||||
|
||||
#include <QApplication>
|
||||
#include "mainwindow.hpp"
|
||||
|
||||
namespace gnc
|
||||
{
|
||||
|
||||
#define APP_GNUCASH "/apps/gnucash"
|
||||
|
||||
/* GNUCASH_SVN is defined whenever we're building from an SVN tree */
|
||||
#ifdef GNUCASH_SVN
|
||||
static int is_development_version = TRUE;
|
||||
#else
|
||||
static int is_development_version = FALSE;
|
||||
#endif
|
||||
|
||||
static gchar **log_flags = NULL;
|
||||
static gchar *log_to_filename = NULL;
|
||||
|
||||
static void
|
||||
gnc_log_init()
|
||||
{
|
||||
if (log_to_filename != NULL)
|
||||
{
|
||||
qof_log_init_filename_special(log_to_filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* initialize logging to our file. */
|
||||
gchar *tracefilename;
|
||||
tracefilename = g_build_filename(g_get_tmp_dir(), "gnucash.trace",
|
||||
(gchar *)NULL);
|
||||
qof_log_init_filename(tracefilename);
|
||||
g_free(tracefilename);
|
||||
}
|
||||
|
||||
// set a reasonable default.
|
||||
qof_log_set_default(QOF_LOG_WARNING);
|
||||
|
||||
gnc_log_default();
|
||||
|
||||
if (gnc_is_debugging())
|
||||
{
|
||||
qof_log_set_level("", QOF_LOG_INFO);
|
||||
qof_log_set_level("qof", QOF_LOG_INFO);
|
||||
qof_log_set_level("gnc", QOF_LOG_INFO);
|
||||
}
|
||||
|
||||
{
|
||||
gchar *log_config_filename;
|
||||
log_config_filename = gnc_build_dotgnucash_path("log.conf");
|
||||
if (g_file_test(log_config_filename, G_FILE_TEST_EXISTS))
|
||||
qof_log_parse_log_config(log_config_filename);
|
||||
g_free(log_config_filename);
|
||||
}
|
||||
|
||||
if (log_flags != NULL)
|
||||
{
|
||||
int i = 0;
|
||||
for (; log_flags[i] != NULL; i++)
|
||||
{
|
||||
QofLogLevel level;
|
||||
gchar **parts = NULL;
|
||||
|
||||
gchar *log_opt = log_flags[i];
|
||||
parts = g_strsplit(log_opt, "=", 2);
|
||||
if (parts == NULL || parts[0] == NULL || parts[1] == NULL)
|
||||
{
|
||||
g_warning("string [%s] not parseable", log_opt);
|
||||
continue;
|
||||
}
|
||||
|
||||
level = qof_log_level_from_string(parts[1]);
|
||||
qof_log_set_level(parts[0], level);
|
||||
g_strfreev(parts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // END namespace gnc
|
||||
|
||||
int
|
||||
main(int argc, char ** argv)
|
||||
{
|
||||
#if !defined(G_THREADS_ENABLED) || defined(G_THREADS_IMPL_NONE)
|
||||
# error "No GLib thread implementation available!"
|
||||
#endif
|
||||
g_thread_init(NULL);
|
||||
|
||||
#ifdef ENABLE_BINRELOC
|
||||
{
|
||||
GError *binreloc_error = NULL;
|
||||
if (!gbr_init(&binreloc_error))
|
||||
{
|
||||
g_print("main: Error on gbr_init: %s\n", binreloc_error->message);
|
||||
g_error_free(binreloc_error);
|
||||
}
|
||||
}
|
||||
#else
|
||||
//g_message("main: binreloc relocation support was disabled at configure time.\n");
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GETTEXT
|
||||
{
|
||||
gchar *localedir = gnc_path_get_localedir();
|
||||
/* setlocale(LC_ALL, ""); is already called by gtk_set_locale()
|
||||
via gtk_init(). */
|
||||
bindtextdomain(GETTEXT_PACKAGE, localedir);
|
||||
textdomain(GETTEXT_PACKAGE);
|
||||
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
|
||||
g_free(localedir);
|
||||
}
|
||||
#endif
|
||||
|
||||
qof_log_init();
|
||||
qof_log_set_default(QOF_LOG_INFO);
|
||||
|
||||
gnc::gnc_log_init();
|
||||
|
||||
gnc_module_system_init();
|
||||
|
||||
qof_backend_module_init();
|
||||
|
||||
// From here on the new C++ code
|
||||
QApplication app(argc, argv);
|
||||
gnc::MainWindow mainWin;
|
||||
mainWin.show();
|
||||
return app.exec();
|
||||
|
||||
}
|
242
src/gnc/mainwindow.cpp
Normal file
242
src/gnc/mainwindow.cpp
Normal file
@ -0,0 +1,242 @@
|
||||
#include <QtGui>
|
||||
|
||||
#include "mainwindow.hpp"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
namespace gnc
|
||||
{
|
||||
|
||||
MainWindow::MainWindow()
|
||||
: ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
createActions();
|
||||
createToolBars();
|
||||
createStatusBar();
|
||||
|
||||
readSettings();
|
||||
|
||||
connect(ui->textEdit->document(), SIGNAL(contentsChanged()),
|
||||
this, SLOT(documentWasModified()));
|
||||
|
||||
setWindowIcon(QIcon(":/pixmaps/gnucash-icon-32x32.png"));
|
||||
|
||||
setCurrentFile("");
|
||||
setUnifiedTitleAndToolBarOnMac(true);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (maybeSave())
|
||||
{
|
||||
writeSettings();
|
||||
event->accept();
|
||||
}
|
||||
else
|
||||
{
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::newFile()
|
||||
{
|
||||
if (maybeSave())
|
||||
{
|
||||
ui->textEdit->clear();
|
||||
setCurrentFile("");
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::open()
|
||||
{
|
||||
if (maybeSave())
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this);
|
||||
if (!fileName.isEmpty())
|
||||
loadFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
bool MainWindow::save()
|
||||
{
|
||||
if (curFile.isEmpty())
|
||||
{
|
||||
return saveAs();
|
||||
}
|
||||
else
|
||||
{
|
||||
return saveFile(curFile);
|
||||
}
|
||||
}
|
||||
|
||||
bool MainWindow::saveAs()
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(this);
|
||||
if (fileName.isEmpty())
|
||||
return false;
|
||||
|
||||
return saveFile(fileName);
|
||||
}
|
||||
|
||||
void MainWindow::about()
|
||||
{
|
||||
QMessageBox::about(this, tr("About Application"),
|
||||
tr("This is a Gnucash C++ gui example, from the Qt4 Application example. It demonstrates how to "
|
||||
"write modern GUI applications using Qt, with a menu bar, "
|
||||
"toolbars, and a status bar."));
|
||||
}
|
||||
|
||||
void MainWindow::documentWasModified()
|
||||
{
|
||||
setWindowModified(ui->textEdit->document()->isModified());
|
||||
}
|
||||
|
||||
void MainWindow::createActions()
|
||||
{
|
||||
ui->actionNew->setShortcuts(QKeySequence::New);
|
||||
ui->actionOpen->setShortcuts(QKeySequence::Open);
|
||||
ui->actionSave->setShortcuts(QKeySequence::Save);
|
||||
ui->actionSave_as->setShortcuts(QKeySequence::SaveAs);
|
||||
|
||||
connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(newFile()));
|
||||
connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(open()));
|
||||
|
||||
connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(save()));
|
||||
connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveAs()));
|
||||
connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(close()));
|
||||
|
||||
connect(ui->actionCut, SIGNAL(triggered()), ui->textEdit, SLOT(cut()));
|
||||
connect(ui->actionCopy, SIGNAL(triggered()), ui->textEdit, SLOT(copy()));
|
||||
connect(ui->actionPaste, SIGNAL(triggered()), ui->textEdit, SLOT(paste()));
|
||||
|
||||
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
|
||||
connect(ui->actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
|
||||
|
||||
ui->actionCut->setEnabled(false);
|
||||
ui->actionCopy->setEnabled(false);
|
||||
connect(ui->textEdit, SIGNAL(copyAvailable(bool)),
|
||||
ui->actionCut, SLOT(setEnabled(bool)));
|
||||
connect(ui->textEdit, SIGNAL(copyAvailable(bool)),
|
||||
ui->actionCopy, SLOT(setEnabled(bool))); // why doesn't this work?!?
|
||||
}
|
||||
|
||||
void MainWindow::createToolBars()
|
||||
{
|
||||
fileToolBar = addToolBar(tr("File"));
|
||||
fileToolBar->addAction(ui->actionNew);
|
||||
fileToolBar->addAction(ui->actionOpen);
|
||||
fileToolBar->addAction(ui->actionSave);
|
||||
|
||||
editToolBar = addToolBar(tr("Edit"));
|
||||
editToolBar->addAction(ui->actionCut);
|
||||
editToolBar->addAction(ui->actionCopy);
|
||||
editToolBar->addAction(ui->actionPaste);
|
||||
}
|
||||
|
||||
void MainWindow::createStatusBar()
|
||||
{
|
||||
statusBar()->showMessage(tr("Ready"));
|
||||
}
|
||||
|
||||
void MainWindow::readSettings()
|
||||
{
|
||||
QSettings settings("Trolltech", "Application Example");
|
||||
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
|
||||
QSize size = settings.value("size", QSize(400, 400)).toSize();
|
||||
resize(size);
|
||||
move(pos);
|
||||
}
|
||||
|
||||
void MainWindow::writeSettings()
|
||||
{
|
||||
QSettings settings("Trolltech", "Application Example");
|
||||
settings.setValue("pos", pos());
|
||||
settings.setValue("size", size());
|
||||
}
|
||||
|
||||
bool MainWindow::maybeSave()
|
||||
{
|
||||
if (ui->textEdit->document()->isModified())
|
||||
{
|
||||
QMessageBox::StandardButton ret;
|
||||
ret = QMessageBox::warning(this, tr("Application"),
|
||||
tr("The document has been modified.\n"
|
||||
"Do you want to save your changes?"),
|
||||
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
|
||||
if (ret == QMessageBox::Save)
|
||||
return save();
|
||||
else if (ret == QMessageBox::Cancel)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::loadFile(const QString &fileName)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Application"),
|
||||
tr("Cannot read file %1:\n%2.")
|
||||
.arg(fileName)
|
||||
.arg(file.errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
ui->textEdit->setPlainText(in.readAll());
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
setCurrentFile(fileName);
|
||||
statusBar()->showMessage(tr("File loaded"), 2000);
|
||||
}
|
||||
|
||||
bool MainWindow::saveFile(const QString &fileName)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QFile::WriteOnly | QFile::Text))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Application"),
|
||||
tr("Cannot write file %1:\n%2.")
|
||||
.arg(fileName)
|
||||
.arg(file.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
out << ui->textEdit->toPlainText();
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
setCurrentFile(fileName);
|
||||
statusBar()->showMessage(tr("File saved"), 2000);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::setCurrentFile(const QString &fileName)
|
||||
{
|
||||
curFile = fileName;
|
||||
ui->textEdit->document()->setModified(false);
|
||||
setWindowModified(false);
|
||||
|
||||
QString shownName;
|
||||
if (curFile.isEmpty())
|
||||
shownName = "untitled.txt";
|
||||
else
|
||||
shownName = strippedName(curFile);
|
||||
|
||||
setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("Application")));
|
||||
}
|
||||
|
||||
QString MainWindow::strippedName(const QString &fullFileName)
|
||||
{
|
||||
return QFileInfo(fullFileName).fileName();
|
||||
}
|
||||
|
||||
} // END namespace gnc
|
62
src/gnc/mainwindow.hpp
Normal file
62
src/gnc/mainwindow.hpp
Normal file
@ -0,0 +1,62 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QSharedPointer>
|
||||
|
||||
class QAction;
|
||||
class QMenu;
|
||||
class QPlainTextEdit;
|
||||
class QTextEdit;
|
||||
class QTabWidget;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
namespace gnc
|
||||
{
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
~MainWindow();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
private slots:
|
||||
void newFile();
|
||||
void open();
|
||||
bool save();
|
||||
bool saveAs();
|
||||
void about();
|
||||
void documentWasModified();
|
||||
|
||||
private:
|
||||
void createActions();
|
||||
void createToolBars();
|
||||
void createStatusBar();
|
||||
void readSettings();
|
||||
void writeSettings();
|
||||
bool maybeSave();
|
||||
void loadFile(const QString &fileName);
|
||||
bool saveFile(const QString &fileName);
|
||||
void setCurrentFile(const QString &fileName);
|
||||
QString strippedName(const QString &fullFileName);
|
||||
|
||||
QSharedPointer<Ui::MainWindow> ui;
|
||||
|
||||
QString curFile;
|
||||
|
||||
QToolBar *fileToolBar;
|
||||
QToolBar *editToolBar;
|
||||
};
|
||||
|
||||
} // END namespace gnc
|
||||
|
||||
#endif
|
258
src/gnc/mainwindow.ui
Normal file
258
src/gnc/mainwindow.ui
Normal file
@ -0,0 +1,258 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>707</width>
|
||||
<height>665</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>GnuCash Qt Example</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="gnc.qrc">
|
||||
<normaloff>:/pixmaps/gnucash-icon-32x32.png</normaloff>:/pixmaps/gnucash-icon-32x32.png</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_1">
|
||||
<attribute name="title">
|
||||
<string>Example Welcome Page</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="textBrowser">
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:18px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt; font-weight:600;">GnuCash C++ Test</span></p>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">This is a text that demonstrates how we can build a GnuCash variant in C++ and Qt.</span></p>
|
||||
<p style=" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt; font-weight:600;">Images</span></p>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><img src=":/pixmaps/gnucash_splash.png" /></p>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">We can also embed images here in this compiled-in HTML page.</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Example Text Editor</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="textEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>707</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionNew"/>
|
||||
<addaction name="actionOpen"/>
|
||||
<addaction name="actionSave"/>
|
||||
<addaction name="actionSave_as"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuHelp">
|
||||
<property name="title">
|
||||
<string>Help</string>
|
||||
</property>
|
||||
<addaction name="actionAbout"/>
|
||||
<addaction name="actionAbout_Qt"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuAccount">
|
||||
<property name="title">
|
||||
<string>Account</string>
|
||||
</property>
|
||||
<addaction name="actionOpenAccount"/>
|
||||
<addaction name="actionNewAccount"/>
|
||||
<addaction name="actionDeleteAccount"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionAccountProperties"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuEdit">
|
||||
<property name="title">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
<addaction name="actionCut"/>
|
||||
<addaction name="actionCopy"/>
|
||||
<addaction name="actionPaste"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuEdit"/>
|
||||
<addaction name="menuAccount"/>
|
||||
<addaction name="menuHelp"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<action name="actionNew">
|
||||
<property name="icon">
|
||||
<iconset resource="gnc.qrc">
|
||||
<normaloff>:/pixmaps/gnc-account-new.png</normaloff>:/pixmaps/gnc-account-new.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&New</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>Create a new file</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+N</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionOpen">
|
||||
<property name="icon">
|
||||
<iconset resource="gnc.qrc">
|
||||
<normaloff>:/pixmaps/gnc-account-open.png</normaloff>:/pixmaps/gnc-account-open.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Open...</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>Open an existing file</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+O</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAbout">
|
||||
<property name="text">
|
||||
<string>About</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>Save the document to disk</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+S</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave_as">
|
||||
<property name="text">
|
||||
<string>Save as...</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>Save the document under a new name</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExit">
|
||||
<property name="text">
|
||||
<string>Exit</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string>Exit the application</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Q</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionNewAccount">
|
||||
<property name="icon">
|
||||
<iconset resource="gnc.qrc">
|
||||
<normaloff>:/pixmaps/gnc-account-new.png</normaloff>:/pixmaps/gnc-account-new.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionOpenAccount">
|
||||
<property name="icon">
|
||||
<iconset resource="gnc.qrc">
|
||||
<normaloff>:/pixmaps/gnc-account-open.png</normaloff>:/pixmaps/gnc-account-open.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Open</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAccountProperties">
|
||||
<property name="icon">
|
||||
<iconset resource="gnc.qrc">
|
||||
<normaloff>:/pixmaps/gnc-account-edit.png</normaloff>:/pixmaps/gnc-account-edit.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Properties...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCut">
|
||||
<property name="text">
|
||||
<string>Cut</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCopy">
|
||||
<property name="text">
|
||||
<string>Copy</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPaste">
|
||||
<property name="text">
|
||||
<string>Paste</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionDeleteAccount">
|
||||
<property name="icon">
|
||||
<iconset resource="gnc.qrc">
|
||||
<normaloff>:/pixmaps/gnc-account-delete.png</normaloff>:/pixmaps/gnc-account-delete.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAbout_Qt">
|
||||
<property name="text">
|
||||
<string>About Qt</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="gnc.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
@ -28,17 +28,17 @@
|
||||
#include <libguile.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib.h>
|
||||
#include "gnc-module.h"
|
||||
#include "gnc-path.h"
|
||||
#include "binreloc.h"
|
||||
#include "gnc-module/gnc-module.h"
|
||||
#include "engine/gnc-path.h"
|
||||
#include "engine/binreloc.h"
|
||||
/* #include "gnc-version.h" */
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-filepath-utils.h"
|
||||
#include "gnc-hooks.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-main.h"
|
||||
#include "gnc-session.h"
|
||||
#include "engine-helpers.h"
|
||||
#include "engine/gnc-engine.h"
|
||||
#include "engine/gnc-filepath-utils.h"
|
||||
#include "engine/gnc-hooks.h"
|
||||
#include "engine/gnc-commodity.h"
|
||||
#include "core-utils/gnc-main.h"
|
||||
#include "engine/gnc-session.h"
|
||||
#include "engine/engine-helpers.h"
|
||||
#include "swig-runtime.h"
|
||||
|
||||
#include "gnc-backend-xml.h"
|
||||
|
Loading…
Reference in New Issue
Block a user