Update of /cvsroot/roadmap/roadmap/src/qt4
In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv3092/qt4
Added Files:
Makefile qt_canvas.cc qt_canvas.h qt_dialog.cc qt_dialog.h
qt_main.cc qt_main.h roadmap_canvas.cc roadmap_dialog.cc
roadmap_fileselection.cc roadmap_main.cc roadmap_messagebox.cc
Log Message:
add initial qt4 support, from oleg gusev
--- NEW FILE: qt_main.cc ---
/* qt_main.cc - A QT implementation for the RoadMap main function.
*
* LICENSE:
*
* (c) Copyright 2003 Latchesar Ionkov
*
* This file is part of RoadMap.
*
* RoadMap 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.
*
* RoadMap 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 RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* SYNOPSYS:
*
* See qt_main.h
*/
#include "qt_main.h"
// Implementation of RMapInput class
RMapInput::RMapInput(int fd1, RoadMapQtInput cb) {
fd = fd1;
callback = cb;
nf = new QSocketNotifier(fd, QSocketNotifier::Read, 0);
connect(nf, SIGNAL(activated(int)), this, SLOT(fire(int)));
}
RMapInput::~RMapInput() {
if (nf) {
delete nf;
nf = 0;
}
}
void RMapInput::fire(int s) {
if (callback != 0) {
callback(s);
}
}
// Implementation of RMapCallback class
RMapCallback::RMapCallback(RoadMapCallback cb) {
callback = cb;
}
void RMapCallback::fire() {
if (callback != 0) {
callback();
}
}
int RMapCallback::same(RoadMapCallback cb) {
return (callback == cb);
}
// Implementation of RMapMainWindow class
RMapMainWindow::RMapMainWindow( QWidget *parent, Qt::WFlags f) : QMainWindow(parent, f) {
spacePressed = false;
for (int i = 0 ; i < ROADMAP_MAX_TIMER; ++i) {
tm[i] = 0;
tcb[i] = 0;
}
canvas = new RMapCanvas(this);
setCentralWidget(canvas);
canvas->setFocus();
//setToolBarsMovable(FALSE);
toolBar = 0;
}
RMapMainWindow::~RMapMainWindow() {
QMap<int, RMapInput*>::Iterator it;
for(it = inputMap.begin(); it != inputMap.end(); ++it) {
//delete it.data();
inputMap.remove(it.key());
}
}
void RMapMainWindow::setKeyboardCallback(RoadMapKeyInput c) {
keyCallback = c;
}
QMenu *RMapMainWindow::newMenu(const char *title) {
return new QMenu(title, this);
}
void RMapMainWindow::freeMenu(QMenu *menu) {
delete (menu);
}
void RMapMainWindow::addMenu(QMenu *menu, const char* label) {
menuBar()->addMenu(menu);
menuBar()->addAction(menu->menuAction());
}
void RMapMainWindow::popupMenu(QMenu *menu, int x, int y) {
if (menu != NULL) menu->popup (mapToGlobal(QPoint (x, y)));
}
void RMapMainWindow::addMenuItem(QMenu *menu,
const char* label,
const char* tip,
RoadMapCallback callback) {
RMapCallback* cb =
new RMapCallback(callback);
QAction *ac = menu->addAction(label);
ac->setToolTip(tip);
connect(ac, SIGNAL(triggered()), cb, SLOT(fire()));
}
void RMapMainWindow::addMenuSeparator(QMenu *menu) {
menu->addSeparator();
}
void RMapMainWindow::addToolbar(const char* orientation) {
if (toolBar == 0) {
toolBar = new QToolBar("map view", 0);
toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
toolBar->setMovable(FALSE);
addToolBar(static_cast<Qt::ToolBarArea>(4), toolBar);
#ifndef QWS
// moveDockWindow not available on QtE v2.3.10.
switch (orientation[0]) {
case 't':
case 'T': break;
case 'b':
case 'B': toolBar->setOrientation(Qt::Horizontal); break;
case 'l':
case 'L': toolBar->setOrientation(Qt::Vertical); break;
case 'r':
case 'R': toolBar->setOrientation(Qt::Vertical); break;
default: roadmap_log (ROADMAP_FATAL,
"Invalid toolbar orientation %s", orientation);
}
#endif
toolBar->setFocusPolicy(Qt::NoFocus);
}
}
void RMapMainWindow::addTool(const char* label,
const char *icon,
const char* tip,
RoadMapCallback callback) {
#ifndef QWS
// For some unknown reason, this toolbar crashes RoadMap
// on the Sharp Zaurus.
// This should be fixed and the ifndef removed.
// Pascal: I believe this has been fixed now.
if (toolBar == 0) {
addToolbar("");
}
if (label != NULL) {
const char *icopath=roadmap_path_search_icon(icon);
QAction* b;
if (icopath)
b = toolBar->addAction(QIcon( QPixmap(icopath) ), label);
else
b = toolBar->addAction(label);
b->setToolTip( QString::fromUtf8(tip) );
//b->setFocusPolicy(Qt::NoFocus);
RMapCallback* cb = new RMapCallback(callback);
connect(b, SIGNAL(triggered()), cb, SLOT(fire()));
}
#endif
}
void RMapMainWindow::addToolSpace(void) {
#ifndef QWS
// For some unknown reason, this toolbar crashes RoadMap
// on the Sharp Zaurus. This should be fixed and the ifndef
// removed.
//addTool (NULL, NULL, NULL, NULL);
toolBar->addSeparator();
#endif
}
void RMapMainWindow::addCanvas(void) {
canvas->configure();
adjustSize();
}
void RMapMainWindow::addInput(int fd, RoadMapQtInput callback) {
RMapInput* rmi = new RMapInput(fd, callback);
inputMap.insert(fd, rmi);
}
void RMapMainWindow::removeInput(int fd) {
RMapInput* rmi = inputMap[fd];
if (rmi != 0) {
inputMap.remove(fd);
delete rmi;
}
}
void RMapMainWindow::setStatus(const char* text) {
//statusBar()->showMessage(text);
}
void RMapMainWindow::keyReleaseEvent(QKeyEvent* event) {
int k = event->key();
if (k == ' ') {
spacePressed = false;
}
event->accept();
}
void RMapMainWindow::keyPressEvent(QKeyEvent* event) {
char* key = 0;
char regular_key[2];
int k = event->key();
switch (k) {
case ' ':
spacePressed = true;
break;
case Qt::Key_Left:
if (spacePressed) {
key = "Button-Calendar";
} else {
key = "Button-Left";
}
break;
case Qt::Key_Right:
if (spacePressed) {
key = "Button-Contact";
} else {
key = "Button-Right";
}
break;
case Qt::Key_Up:
key = "Button-Up";
break;
case Qt::Key_Down:
key = "Button-Down";
break;
default:
if (k>0 && k<128) {
regular_key[0] = k;
regular_key[1] = 0;
key = regular_key;
}
}
if (key!=0 && keyCallback!=0) {
keyCallback(key);
}
event->accept();
}
void RMapMainWindow::closeEvent(QCloseEvent* ev) {
roadmap_main_exit();
ev->accept();
}
void RMapMainWindow::setTimer(int interval, RoadMapCallback callback) {
int empty = -1;
for (int i = 0; i < ROADMAP_MAX_TIMER; ++i) {
if (tm[i] == 0) {
empty = i;
} else if (tcb[i]->same(callback)) {
return;
}
}
if (empty < 0) {
roadmap_log (ROADMAP_ERROR, "too many timers");
}
tm[empty] = new QTimer(this);
tcb[empty] = new RMapCallback(callback);
connect(tm[empty], SIGNAL(timeout()), tcb[empty], SLOT(fire()));
tm[empty]->start(interval);
}
void RMapMainWindow::removeTimer(RoadMapCallback callback) {
int found = -1;
for (int i = 0; i < ROADMAP_MAX_TIMER; ++i) {
if (tcb[i] != 0) {
if (tcb[i]->same(callback)) {
found = i;
break;
}
}
}
if (found < 0) return;
tm[found]->stop();
delete tm[found];
delete tcb[found];
tm[found] = 0;
tcb[found] = 0;
}
--- NEW FILE: roadmap_fileselection.cc ---
/* roadmap_fileselection.cc - A C to C++ wrapper for the QT RoadMap file dialogs
*
* LICENSE:
*
* (c) Copyright 2003 Latchesar Ionkov
*
* This file is part of RoadMap.
*
* RoadMap 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.
*
* RoadMap 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 RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* SYNOPSYS:
*
* See roadmap_fileselection.h
*/
extern "C" {
#include "roadmap_fileselection.h"
}
#include <qfiledialog.h>
void roadmap_fileselection_new (const char *title, const char *filter,
const char *path, const char *mode, RoadMapFileCallback callback) {
QFileDialog *dlg = new QFileDialog(0, title );
if (mode[0] == 'w') {
dlg->setFileMode( QFileDialog::AnyFile );
} else {
dlg->setFileMode( QFileDialog::ExistingFile );
}
dlg->setViewMode(QFileDialog::Detail);
if ( dlg->exec() ) {
QString result;
result = dlg->selectedFiles().first();
delete dlg;
callback (result.toLatin1().data(), mode);
} else {
delete dlg;
}
}
--- NEW FILE: qt_dialog.cc ---
/* qt_dialog.cc - A QT implementation for the RoadMap dialogs
*
* LICENSE:
*
* (c) Copyright 2003 Latchesar Ionkov
*
* This file is part of RoadMap.
*
* RoadMap 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.
*
* RoadMap 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 RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* SYNOPSYS:
*
* See qt_dialog.h
*/
#include <stdio.h>
#include "qt_dialog.h"
#include <qlayout.h>
#include <qboxlayout.h>
// Implementation of RMapDialog class
RMapDialog::RMapDialog( QWidget *parent, Qt::WFlags f ):QDialog(parent, f) {
}
RMapDialog::~RMapDialog() {
}
QMap<int, Entry *>* RMapDialog::getFrame(QString frameName) {
QMap<int, Entry *>* frame = frames[frameName];
if (frame == 0) {
frame = new QMap<int, Entry*>;
frameNames.append(QString(frameName));
frames.insert(frameName, frame);
}
return frame;
}
Entry* RMapDialog::getEntry(QString frameName, QString entryName) {
QMap<int, Entry *>* frame = frames[frameName];
if (frame == 0) {
return 0;
}
int i;
for (i=0; i<frame->count(); i++) {
if (frame->value(i)->getName() == entryName)
return frame->value(i);
}
return 0;
}
void RMapDialog::addTextEntry(const char* frameName, const char* name) {
QMap<int, Entry *>* frame = getFrame(frameName);
Entry *entry = new Entry(this, Entry::TextEntry, name);
frame->insert(frame->count(),entry);
}
void RMapDialog::addLabelEntry(const char* frameName, const char* name) {
QMap<int, Entry *>* frame = getFrame(frameName);
Entry *entry = new Entry(this, Entry::LabelEntry, name);
frame->insert(frame->count(),entry);
}
void RMapDialog::addColorEntry(const char* frameName, const char* name) {
addTextEntry(frameName, name);
}
void RMapDialog::addChoiceEntry(const char* frameName,
const char* name,
int count,
int current,
char** labels,
void** values,
RoadMapDialogCallback callback) {
QMap<int, Entry *>* frame = getFrame(frameName);
QVector<Item> items(count);
for(int i = 0; i < count; i++) {
items[i].label = labels[i];
items[i].value = values[i];
}
Entry *entry =
new Entry(this, Entry::ChoiceEntry, name, items, current, callback);
frame->insert(frame->count(),entry);
}
void RMapDialog::addListEntry(const char* frameName, const char* name) {
QMap<int, Entry *>* frame = getFrame(frameName);
Entry *entry = new Entry(this, Entry::ListEntry, name);
frame->insert(frame->count(),entry);
}
void RMapDialog::setListEntryValues(const char* frameName, const char* name,
int count, char** labels, void** values, RoadMapDialogCallback callback) {
Entry *entry = getEntry(frameName, name);
if (entry == 0) {
return;
}
QVector<Item> items(count);
for(int i = 0; i < count; i++) {
items[i].label = labels[i];
items[i].value = values[i];
}
entry->setValues(items, callback);
}
void RMapDialog::addButton(char* label, RoadMapDialogCallback callback) {
QVector<Item> items;
Entry *entry =
new Entry(this, Entry::ButtonEntry, label, items, 0, callback);
buttons.append(entry);
}
void RMapDialog::addHiddenEntry(const char* frameName, const char* name) {
QMap<int, Entry *>* frame = getFrame(frameName);
Entry *entry = new Entry(this, Entry::HiddenEntry, name);
frame->insert(frame->count(),entry);
}
void RMapDialog::complete(int) {
QVBoxLayout* main = new QVBoxLayout(this);
QWidget* topw = 0;
main->setSpacing(4);
main->setMargin(2);
if (frames.count() > 1) {
QTabWidget* tw = new QTabWidget(this);
for(int i = 0; i < frameNames.size();
++i) {
QMap<int, Entry *>* frame = frames[frameNames.at(i)];
QWidget* w = new QWidget(tw);
initTab(w, frame);
tw->addTab(w, frameNames.at(i));
}
topw = tw;
} else {
topw = new QWidget(this);
initTab(topw, *frames.begin());
}
QWidget* bw = new QWidget(this);
QHBoxLayout* btns = new QHBoxLayout(bw);
Entry *entry;
for(int i=0; i<buttons.size(); i++) {
entry = buttons.at(i);
QWidget* w = entry->create(bw);
btns->addWidget(w);
}
main->addWidget(topw);
main->addWidget(bw);
adjustSize();
show();
}
void* RMapDialog::getEntryValue(const char* frame, const char* name) {
Entry *entry = getEntry(frame, name);
if (entry == 0) {
return 0;
}
return entry->getValue();
}
void RMapDialog::setEntryValue(const char* frame, const char* name, const void* data) {
Entry *entry = getEntry(frame, name);
if (entry == 0) {
return;
}
return entry->setValue(data);
}
void RMapDialog::initTab(QWidget* tab, QMap<int, Entry *>* entries) {
QGridLayout* grid = new QGridLayout(tab); //, entries->count(), 2, 2, 5);
Entry* entry;
for(int i = 0; i < entries->count(); i++) {
entry = entries->value(i);
QWidget* w = entry->create(tab);
QLabel* l;
if (entry->getWidget() != 0) {
if (entry->getName()[0] == '.') {
grid->addWidget(w, i, i, 0, 1);
} else {
l = new QLabel(entry->getName(), tab,0 );
grid->addWidget(l, i, 0);
grid->addWidget(w, i, 1);
}
}
}
}
void RMapDialog::setContext(void* ctx) {
context = ctx;
}
// Implementation of Entry class
Entry::Entry(RMapDialog* dlg, int etype, QString ename) {
dialog = dlg;
type = etype;
name = ename;
callback = 0;
widget = 0;
current = 0;
value = 0;
}
Entry::Entry(RMapDialog* dlg, int etype, QString ename, QVector<Item>& eitems,
int ecurrent, RoadMapDialogCallback ecallback) {
dialog = dlg;
type = etype;
name = ename;
current = ecurrent;
callback = ecallback;
value = 0;
items.resize(eitems.count());
for(int i = 0; i < eitems.count(); i++) {
items.insert(i, eitems[i]);
}
}
Entry::~Entry() {
}
QWidget* Entry::create(QWidget* parent) {
widget = 0;
switch (type) {
case TextEntry:
widget = new QLineEdit(parent);
break;
case ColorEntry:
widget = new QLineEdit(parent);
break;
case ChoiceEntry:
{
QComboBox* cb = new QComboBox(parent);
cb->setEditable(false);
for(int i = 0; i < items.count(); i++) {
cb->addItem(items[i].label);
}
cb->setCurrentIndex(current);
connect(cb, SIGNAL(activated(int)), this, SLOT(run()));
widget = cb;
}
break;
case ListEntry:
{
QListWidget* lb = new QListWidget(parent);
widget = lb;
// ugly hack ...
lb->setMinimumHeight(200);
lb->setMinimumWidth(150);
connect(widget, SIGNAL(currentRowChanged(int)), this, SLOT(run()));
}
break;
case ButtonEntry:
widget = new QPushButton(parent);
widget->setObjectName(name);
((QPushButton *)widget)->setText(name);
connect(widget, SIGNAL(clicked()), this, SLOT(run()));
break;
case LabelEntry:
widget = new QLabel(parent);
((QLabel *)widget)->setAlignment (Qt::AlignRight|Qt::AlignVCenter);
break;
case HiddenEntry:
break;
}
return widget;
}
QString Entry::getName() {
return name;
}
void* Entry::getValue() {
void* ret = 0;
switch (type) {
case TextEntry:
{
QString s = ((QLineEdit*) widget)->text();
const char* ss = s.toLatin1();
ret = (void *) ss;
}
break;
case ColorEntry:
ret = (void *) (const char*) ((QLineEdit*) widget)->text().toLatin1();
break;
case ChoiceEntry:
ret = items[((QComboBox*) widget)->currentIndex()].value;
break;
case ListEntry:
ret = items[((QListWidget*) widget)->currentIndex().row()].value;
break;
case HiddenEntry:
ret = (void *)value;
break;
}
return ret;
}
void Entry::setValue(const void* val) {
switch (type) {
case TextEntry:
((QLineEdit*) widget)->setText((char*) val);
break;
case ColorEntry:
((QLineEdit*) widget)->setText((char*) val);
break;
case ChoiceEntry:
for (int i = 0; i < items.count(); ++i) {
if (items[i].value == val) {
((QComboBox*) widget)->setCurrentIndex(i);
break;
}
}
break;
case ListEntry:
for (int i = 0; i < items.count(); ++i) {
if (items[i].value == val) {
((QListWidget*) widget)->setCurrentRow(i);
break;
}
}
break;
case LabelEntry:
((QLabel*) widget)->setText((char *)val);
break;
case HiddenEntry:
value = val;
break;
}
}
void Entry::setValues(QVector<Item>& eitems,
RoadMapDialogCallback cb) {
if (type != ListEntry) {
return;
}
QListWidget* lb = (QListWidget*) widget;
if (lb->count() > 0) lb->clear();
items.resize(eitems.count());
for(int i = 0; i < eitems.count(); i++) {
items.insert(i, eitems[i]);
lb->addItem(eitems[i].label);
}
callback = cb;
}
void Entry::run() {
if (callback != 0) {
callback(name.toAscii().constData(), dialog->getContext());
}
}
--- NEW FILE: qt_canvas.h ---
/* qt_canvas.h - The interface for the RoadMap/QT canvas class.
*
* LICENSE:
*
* (c) Copyright 2003 Latchesar Ionkov
*
* This file is part of RoadMap.
*
* RoadMap 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.
*
* RoadMap 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 RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef INCLUDE__ROADMAP_QT_CANVAS__H
#define INCLUDE__ROADMAP_QT_CANVAS__H
#include <qwidget.h>
#include <qpen.h>
#include <qmap.h>
#include <qpixmap.h>
#include <qpainter.h>
#include <qevent.h>
extern "C" {
#include "roadmap.h"
#include "roadmap_types.h"
#include "roadmap_gui.h"
#include "roadmap_canvas.h"
struct roadmap_canvas_pen {
QPen* pen;
};
};
class RMapCanvas : public QWidget {
Q_OBJECT
public:
RMapCanvas(QWidget* parent);
virtual ~RMapCanvas();
RoadMapPen createPen(const char* name);
void selectPen(RoadMapPen);
void setPenColor(const char* color);
void setPenLineStyle(const char* style);
void setPenThickness(int thickness);
void erase(void);
void drawString(RoadMapGuiPoint* position, int corner,
const char* text);
void drawStringAngle(RoadMapGuiPoint* position,
int center, const char* text, int angle);
void drawMultiplePoints(int count, RoadMapGuiPoint* points);
void drawMultipleLines(int count, int* lines, RoadMapGuiPoint* points);
void drawMultiplePolygons(int count, int* polygons,
RoadMapGuiPoint* points, int filled);
void drawMultipleCircles(int count, RoadMapGuiPoint* centers,
int* radius, int filled);
void registerButtonPressedHandler(RoadMapCanvasMouseHandler handler);
void registerButtonReleasedHandler(RoadMapCanvasMouseHandler handler);
void registerMouseMoveHandler(RoadMapCanvasMouseHandler handler);
void registerMouseWheelHandler(RoadMapCanvasMouseHandler handler);
void registerConfigureHandler(RoadMapCanvasConfigureHandler handler);
void getTextExtents(const char* text, int* width, int* ascent,
int* descent, int *can_tilt);
int getHeight();
int getWidth();
void refresh(void);
void configure();
protected:
QMap<QString, QColor*> colors;
QMap<QString, RoadMapPen> pens;
QPen* currentPen;
QPixmap* pixmap;
RoadMapCanvasConfigureHandler configureHandler;
RoadMapCanvasMouseHandler buttonPressedHandler;
RoadMapCanvasMouseHandler buttonReleasedHandler;
RoadMapCanvasMouseHandler mouseMoveHandler;
RoadMapCanvasMouseHandler mouseWheelHandler;
void initColors();
QColor getColor(const char* color);
virtual void mousePressEvent(QMouseEvent*);
virtual void mouseReleaseEvent(QMouseEvent*);
virtual void mouseMoveEvent(QMouseEvent*);
virtual void wheelEvent(QWheelEvent*);
virtual void resizeEvent(QResizeEvent*);
virtual void paintEvent(QPaintEvent*);
};
extern RMapCanvas *roadMapCanvas;
extern RoadMapCanvasMouseHandler phandler;
extern RoadMapCanvasMouseHandler rhandler;
extern RoadMapCanvasMouseHandler mhandler;
extern RoadMapCanvasMouseHandler whandler;
extern RoadMapCanvasConfigureHandler chandler;
#endif
--- NEW FILE: roadmap_messagebox.cc ---
/* roadmap_messagebox.cc - The C to C++ wrapper for the QT RoadMap message box.
*
* LICENSE:
*
* (c) Copyright 2003 Latchesar Ionkov
*
* This file is part of RoadMap.
*
* RoadMap 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.
*
* RoadMap 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 RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* SYNOPSYS:
*
* See roadmap_messagebox.h
*/
#include <qmessagebox.h>
extern "C" {
#include "roadmap_start.h"
#include "roadmap_messagebox.h"
}
void roadmap_messagebox(const char* title, const char* message) {
//QMessageBox::information(0, roadmap_start_get_title(title), message)
}
void roadmap_messagebox_wait(const char* title, const char* message) {
//QMessageBox::critical(0, roadmap_start_get_title(title), message);
}
--- NEW FILE: Makefile ---
# QT makefile
TOP = ..
include $(TOP)/options.mk
# --- Installation options -------------------------------------------------
desktopdir=$(INSTALLDIR)/apps/Applications
MOC=$(QTDIR)/bin/moc
# --- QT-specific options ------------------------------------------------
ifeq ($(DESKTOP),QT4)
CFLAGS += -I$(QTDIR)/include -I$(QTDIR)/include/Qt -I$(QTDIR)/include/QtGui
CFLAGS += -fno-rtti -fno-exceptions -DQT4
LIBS += -L$(QTDIR)/lib -lQtCore -lQtGui -lpthread
#MOC=$(QTDIR)/bin/moc-qt4
endif
ifeq ($(DESKTOP),QPE4)
CFLAGS += -I$(QTDIR)/include -I$(QTDIR)/include/Qt
CFLAGS += -I$(QTDIR)/include/QtGui -DQWS
LIBS += -L$(QTDIR)/lib -lQtCore -lQtGui -lQtSql -lQtSvg -lQtNetwork -lQtXml -lts
INSTALLDIR=$(QTDIR)
endif
# --- QT sources & targets --------------------------------------------
RMLIBSRCS = qt_main.cc \
moc_qt_main.cc \
qt_canvas.cc \
moc_qt_canvas.cc \
qt_dialog.cc \
moc_qt_dialog.cc \
roadmap_dialog.cc \
roadmap_fileselection.cc \
roadmap_messagebox.c
RMLIBOBJS1 = $(RMLIBSRCS:.cc=.o)
RMLIBOBJS = $(CANVAS_OBJS) $(RMLIBOBJS1:.c=.o)
TARGETS = qtroadgps qtroadmap
# --- Conventional targets ----------------------------------------
.PHONY: all clean strip install install-ipkg uninstall
all: $(TARGETS)
clean:
rm -f *~ *.o *.a *.da $(TARGETS) moc_qt_*.cc
strip:
$(STRIP) $(TARGETS)
install:
mkdir -p $(DESTDIR)$(bindir)
cd $(DESTDIR)$(bindir) && rm -f $(TARGETS) roadmap roadgps
install $(TARGETS) $(DESTDIR)$(bindir)/
ln -s qtroadmap $(DESTDIR)$(bindir)/roadmap
ln -s qtroadgps $(DESTDIR)$(bindir)/roadgps
cd $(DESTDIR)$(bindir) ; $(STRIP) $(TARGETS)
install-ipkg: install
mkdir -p $(DESTDIR)$(desktopdir)
install ipkg/zroadmap.desktop $(DESTDIR)$(desktopdir)
install ipkg/zroadgps.desktop $(DESTDIR)$(desktopdir)
# These no longer exists. Do not try to install them. It will fail
# mkdir -p $(DESTDIR)$(INSTALLDIR)/pics
mkdir -p $(DESTDIR)$(pkgdatadir)
# install ipkg/zroadmap.png $(DESTDIR)$(INSTALLDIR)/pics
# install ipkg/zroadgps.png $(DESTDIR)$(INSTALLDIR)/pics
# install ipkg/preferences $(DESTDIR)$(pkgdatadir)
uninstall:
cd $(bindir) && rm -f $(TARGETS) roadmap roadgps
# temporary
roadmap_canvas_agg.o:
@echo
@echo "*** Sorry! We still need a roadmap_canvas_agg.cc for QT."
@echo
false
# --- The real targets --------------------------------------------
libqtroadmap.a: $(RMLIBOBJS)
$(AR) $(ARFLAGS) libqtroadmap.a $(RMLIBOBJS)
$(RANLIB) libqtroadmap.a
qtroadmap: roadmap_main.o libqtroadmap.a \
$(TOP)/libguiroadmap.a $(filter %.a, $(LIBS))
$(CXX) $(LDFLAGS) -o qtroadmap roadmap_main.o \
$(TOP)/libguiroadmap.a libqtroadmap.a $(LIBS)
qtroadgps: roadmap_main.o libqtroadmap.a \
$(TOP)/libguiroadgps.a $(filter %.a, $(LIBS))
$(CXX) $(LDFLAGS) -o qtroadgps roadmap_main.o \
$(TOP)/libguiroadgps.a libqtroadmap.a $(LIBS)
moc_qt_main.cc: qt_main.h
$(MOC) qt_main.h -o moc_qt_main.cc
moc_qt_canvas.cc: qt_canvas.h
$(MOC) qt_canvas.h -o moc_qt_canvas.cc
moc_qt_dialog.cc: qt_dialog.h
$(MOC) qt_dialog.h -o moc_qt_dialog.cc
--- NEW FILE: roadmap_dialog.cc ---
/* roadmap_dialog.cc - A C to C++ wrapper for the QT RoadMap dialogs
*
* LICENSE:
*
* (c) Copyright 2003 Latchesar Ionkov
*
* This file is part of RoadMap.
*
* RoadMap 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.
*
* RoadMap 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 RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* SYNOPSYS:
*
* See roadmap_dialog.h
*/
extern "C" {
#include "roadmap.h"
#include "roadmap_types.h"
#include "roadmap_start.h"
#include "roadmap_dialog.h"
};
#include "qt_dialog.h"
QMap<QString, RMapDialog*> dialogs;
RMapDialog* currentDialog;
int roadmap_dialog_activate(const char* name, void* context) {
RMapDialog* dialog = dialogs[name];
int ret = 0;
if (dialog != 0) {
dialog->show();
ret = 0;
} else {
dialog = new RMapDialog(0, 0);
dialog->setWindowTitle(name);
dialogs[name] = dialog;
ret = 1;
}
currentDialog = dialog;
currentDialog->setContext(context);
return ret;
}
void roadmap_dialog_hide(const char* name) {
// RMapDialog* dialog = dialogs[name];
if (currentDialog != 0) {
currentDialog->hide();
}
}
void roadmap_dialog_new_entry (const char *frame, const char *name) {
currentDialog->addTextEntry(frame, name);
}
void roadmap_dialog_new_label (const char *frame, const char *name) {
currentDialog->addLabelEntry(frame, name);
}
void roadmap_dialog_new_color (const char *frame, const char *name) {
currentDialog->addColorEntry(frame, name);
}
void roadmap_dialog_new_choice (const char *frame,
const char *name,
int count,
int current,
char **labels,
void **values,
RoadMapDialogCallback callback) {
currentDialog->addChoiceEntry
(frame, name, count, current, labels, values, callback);
}
void roadmap_dialog_new_list (const char *frame, const char *name) {
currentDialog->addListEntry(frame, name);
}
void roadmap_dialog_new_hidden (const char *frame, const char *name) {
currentDialog->addHiddenEntry(frame, name);
}
void roadmap_dialog_show_list (const char* frame, const char* name, int count,
char **labels, void **values, RoadMapDialogCallback callback) {
currentDialog->setListEntryValues(frame, name, count, labels, values, callback);
}
void roadmap_dialog_add_button (char *label, RoadMapDialogCallback callback) {
currentDialog->addButton(label, callback);
}
void roadmap_dialog_complete (int use_keyboard) {
currentDialog->complete(use_keyboard);
}
void roadmap_dialog_select(const char *dialog) {
RMapDialog* d = dialogs[dialog];
if (d != 0) {
currentDialog = d;
}
}
void *roadmap_dialog_get_data (const char *frame, const char *name) {
return currentDialog->getEntryValue(frame, name);
}
void roadmap_dialog_set_data (const char *frame, const char *name,
const void *data) {
currentDialog->setEntryValue(frame, name, data);
}
--- NEW FILE: qt_dialog.h ---
/* qt_dialog.h - The interface for the RoadMap/QT dialog class.
*
* LICENSE:
*
* (c) Copyright 2003 Latchesar Ionkov
*
* This file is part of RoadMap.
*
* RoadMap 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.
*
* RoadMap 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 RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <qdialog.h>
#include <qwidget.h>
#include <qlist.h>
//#include <qarray.h>
#include <qpushbutton.h>
#include <qlineedit.h>
#include <qcombobox.h>
#include <qlayout.h>
#include <qtabwidget.h>
#include <qlabel.h>
#include <qlistwidget.h>
#include <qvector.h>
#include <qlist.h>
#include <qmap.h>
#include "roadmap.h"
#include "roadmap_types.h"
#include "roadmap_dialog.h"
struct Item {
QString label;
void* value;
};
class RMapDialog;
class Entry : public QObject {
Q_OBJECT
protected:
RMapDialog* dialog;
int type;
QString name;
RoadMapDialogCallback callback;
QVector<Item> items;
int current;
QWidget* widget;
const void* value;
public:
enum {
TextEntry = 1,
ColorEntry,
ChoiceEntry,
ListEntry,
ButtonEntry,
LabelEntry,
HiddenEntry,
};
Entry(RMapDialog* dialog, int type, QString name);
Entry(RMapDialog* dialog, int type, QString name, QVector<Item>& items,
int current, RoadMapDialogCallback callback);
~Entry();
QWidget* create(QWidget* parent);
QString getName();
void* getValue();
void setValue(const void*);
QWidget* getWidget() {
return widget;
}
void setValues(QVector<Item>& items,
RoadMapDialogCallback callback);
protected slots:
void run();
};
class RMapDialog : public QDialog {
Q_OBJECT
public:
RMapDialog( QWidget *parent = 0, Qt::WFlags f = 0 );
virtual ~RMapDialog();
void addTextEntry(const char* frame, const char* name);
void addLabelEntry(const char* frame, const char* name);
void addHiddenEntry(const char* frame, const char* name);
void addColorEntry(const char* frame, const char* name);
void addChoiceEntry(const char* frame,
const char* name,
int count,
int current,
char** labels,
void** values,
RoadMapDialogCallback callback);
void addListEntry(const char* frame, const char* name);
void setListEntryValues(const char* frame, const char* name, int count,
char** labels, void** values, RoadMapDialogCallback callback);
void addButton(char* label, RoadMapDialogCallback callback);
void complete(int use_keyboard);
void* getEntryValue(const char* frame, const char* name);
void setEntryValue(const char* frame, const char* name, const void* data);
void setContext(void*);
void* getContext() {
return context;
}
protected:
QMap<QString, QMap<int, Entry *> *> frames;
QList<QString> frameNames;
QList<Entry *> buttons;
void* context;
QMap<int, Entry*>* getFrame(QString frameName);
Entry* getEntry(QString frameName, QString entryName);
void initTab(QWidget* w, QMap<int, Entry*>* entries);
};
--- NEW FILE: roadmap_canvas.cc ---
/* roadmap_canvas.cc - A C to C++ wrapper for the QT RoadMap canvas
*
* LICENSE:
*
* (c) Copyright 2003 Latchesar Ionkov
*
* This file is part of RoadMap.
*
* RoadMap 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.
*
* RoadMap 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 RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* SYNOPSYS:
*
* See roadmap_canvas.h
*/
extern "C" {
#include "roadmap.h"
#include "roadmap_types.h"
#include "roadmap_gui.h"
#include "roadmap_canvas.h"
}
#include "qimage.h"
#include "qt_canvas.h"
void roadmap_canvas_register_button_pressed_handler(RoadMapCanvasMouseHandler handler) {
if (roadMapCanvas) {
roadMapCanvas->registerButtonPressedHandler(handler);
} else {
phandler = handler;
}
}
void roadmap_canvas_register_button_released_handler(RoadMapCanvasMouseHandler handler) {
if (roadMapCanvas) {
roadMapCanvas->registerButtonReleasedHandler(handler);
} else {
rhandler = handler;
}
}
void roadmap_canvas_register_mouse_move_handler(RoadMapCanvasMouseHandler handler) {
if (roadMapCanvas) {
roadMapCanvas->registerMouseMoveHandler(handler);
} else {
mhandler = handler;
}
}
void roadmap_canvas_register_mouse_scroll_handler
(RoadMapCanvasMouseHandler handler) {
if (roadMapCanvas) {
roadMapCanvas->registerMouseWheelHandler(handler);
} else {
whandler = handler;
}
}
void roadmap_canvas_register_configure_handler(
RoadMapCanvasConfigureHandler handler) {
if (roadMapCanvas) {
roadMapCanvas->registerConfigureHandler(handler);
} else {
chandler = handler;
}
}
void roadmap_canvas_get_text_extents(const char *text, int size,
int *width, int *ascent, int *descent, int *can_tilt) {
roadMapCanvas->getTextExtents(text, width, ascent, descent, can_tilt);
}
RoadMapPen roadmap_canvas_create_pen (const char *name) {
return roadMapCanvas->createPen(name);
}
RoadMapPen roadmap_canvas_select_pen (RoadMapPen pen) {
static RoadMapPen CurrentPen;
RoadMapPen old_pen = CurrentPen;
CurrentPen = pen;
roadMapCanvas->selectPen(pen);
return old_pen;
}
void roadmap_canvas_set_foreground (const char *color) {
roadMapCanvas->setPenColor(color);
}
void roadmap_canvas_set_linestyle (const char *style) {
roadMapCanvas->setPenLineStyle(style);
}
void roadmap_canvas_set_thickness (int thickness) {
roadMapCanvas->setPenThickness(thickness);
}
void roadmap_canvas_erase (void) {
roadMapCanvas->erase();
}
void roadmap_canvas_draw_string(RoadMapGuiPoint *position, int corner,
const char *text) {
roadMapCanvas->drawString(position, corner, text);
}
void roadmap_canvas_draw_string_angle (RoadMapGuiPoint *position,
RoadMapGuiPoint *center,
int angle, const char *text)
{
roadMapCanvas->drawStringAngle(position, 0, text, angle);
}
void roadmap_canvas_draw_multiple_points (int count, RoadMapGuiPoint *points) {
roadMapCanvas->drawMultiplePoints(count, points);
}
void roadmap_canvas_draw_multiple_lines(int count, int *lines,
RoadMapGuiPoint *points, int fast_draw) {
roadMapCanvas->drawMultipleLines(count, lines, points);
}
void roadmap_canvas_draw_multiple_polygons(int count, int *polygons,
RoadMapGuiPoint *points, int filled, int fast_draw) {
roadMapCanvas->drawMultiplePolygons(count, polygons, points, filled);
}
void roadmap_canvas_draw_multiple_circles(int count, RoadMapGuiPoint *centers,
int *radius, int filled, int fast_draw) {
roadMapCanvas->drawMultipleCircles(count, centers, radius, filled);
}
int roadmap_canvas_width (void) {
return roadMapCanvas->getWidth();
}
int roadmap_canvas_height (void) {
return roadMapCanvas->getHeight();
}
void roadmap_canvas_refresh (void) {
roadMapCanvas->refresh();
}
void roadmap_canvas_save_screenshot (const char* filename) {
QPixmap pixmap;
QString name (filename);
pixmap = QPixmap::grabWidget (roadMapCanvas);
pixmap.save (name, "PNG");
}
--- NEW FILE: qt_main.h ---
/* qt_main.h - The interface for the RoadMap/QT main class.
*
* LICENSE:
*
* (c) Copyright 2003 Latchesar Ionkov
*
* This file is part of RoadMap.
*
* RoadMap 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.
*
* RoadMap 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 RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef INCLUDE__ROADMAP_QT_MAIN__H
#define INCLUDE__ROADMAP_QT_MAIN__H
#include <qmainwindow.h>
#include <qmap.h>
#include <qtoolbar.h>
#include <qmenubar.h>
#include <qmenu.h>
#include <qsocketnotifier.h>
#include <qpushbutton.h>
#include <qstatusbar.h>
#include <qtimer.h>
#include <qtooltip.h>
#include <qevent.h>
#include <qicon.h>
#define ROADMAP_MAX_TIMER 16
extern "C" {
#include "roadmap.h"
#include "roadmap_start.h"
#include "roadmap_config.h"
#include "roadmap_history.h"
#include "roadmap_main.h"
#include "roadmap_path.h"
typedef void (*RoadMapQtInput) (int fd);
};
#include "qt_canvas.h"
class RMapInput : public QObject {
Q_OBJECT
public:
RMapInput(int fd1, RoadMapQtInput cb);
~RMapInput();
protected:
int fd;
RoadMapQtInput callback;
QSocketNotifier* nf;
protected slots:
void fire(int);
};
class RMapCallback : public QObject {
Q_OBJECT
public:
RMapCallback(RoadMapCallback cb);
int same (RoadMapCallback cb);
protected slots:
void fire();
protected:
RoadMapCallback callback;
};
class RMapMainWindow : public QMainWindow {
Q_OBJECT
public:
RMapMainWindow( QWidget *parent, Qt::WFlags f);
virtual ~RMapMainWindow();
void setKeyboardCallback(RoadMapKeyInput c);
QMenu *newMenu(const char *title);
void freeMenu(QMenu *menu);
void addMenu(QMenu *menu, const char* label);
void popupMenu(QMenu *menu, int x, int y);
void addMenuItem(QMenu *menu,
const char* label,
const char* tip,
RoadMapCallback callback);
void addMenuSeparator(QMenu *menu);
void addToolbar(const char* orientation);
void addTool(const char* label, const char *icon, const char* tip,
RoadMapCallback callback);
void addToolSpace(void);
void addCanvas(void);
void addInput(int fd, RoadMapQtInput callback);
void removeInput(int fd);
void setStatus(const char* text);
void setTimer(int interval, RoadMapCallback callback);
void removeTimer(RoadMapCallback callback);
protected:
RoadMapKeyInput keyCallback;
QMap<int, RMapInput*> inputMap;
QToolBar* toolBar;
RMapCanvas* canvas;
QTimer* tm[ROADMAP_MAX_TIMER];
RMapCallback* tcb[ROADMAP_MAX_TIMER];
bool spacePressed;
virtual void keyPressEvent(QKeyEvent* event);
virtual void keyReleaseEvent(QKeyEvent* event);
virtual void closeEvent(QCloseEvent* ev);
};
extern RMapMainWindow* mainWindow;
#endif
--- NEW FILE: qt_canvas.cc ---
/* qt_canvas.cc - A QT implementation for the RoadMap canvas
*
* LICENSE:
*
* (c) Copyright 2003 Latchesar Ionkov
*
* This file is part of RoadMap.
*
* RoadMap 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.
*
* RoadMap 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 RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* SYNOPSYS:
*
* See qt_canvas.h
*/
#include <stdio.h>
#include <stdlib.h>
#include <qpolygon.h>
#include <qpainter.h>
#include "qt_canvas.h"
RMapCanvas *roadMapCanvas = 0;
RoadMapCanvasMouseHandler phandler = 0;
RoadMapCanvasMouseHandler rhandler = 0;
RoadMapCanvasMouseHandler mhandler = 0;
RoadMapCanvasMouseHandler whandler = 0;
RoadMapCanvasConfigureHandler chandler = 0;
// Implementation of RMapCanvas class
RMapCanvas::RMapCanvas(QWidget* parent):QWidget(parent) {
pixmap = 0;
currentPen = 0;
roadMapCanvas = this;
initColors();
registerButtonPressedHandler(phandler);
registerButtonReleasedHandler(rhandler);
registerMouseMoveHandler(mhandler);
registerMouseWheelHandler(whandler);
registerConfigureHandler(chandler);
//setBackgroundMode(Qt::NoBackground);
//setAttribute(Qt::WA_NoBackgrond);
}
RMapCanvas::~RMapCanvas() {
if (pixmap != 0) {
delete pixmap;
pixmap = 0;
}
// TODO: delete pens
}
RoadMapPen RMapCanvas::createPen(const char* name) {
RoadMapPen p = pens[name];
if (p == 0) {
QPen* pen = new QPen(Qt::SolidLine/*Qt::DotLine*/);
p = new roadmap_canvas_pen();
p->pen = pen;
pens.insert(name, p);
}
currentPen = p->pen;
return p;
}
void RMapCanvas::selectPen(RoadMapPen p) {
currentPen = p->pen;
}
void RMapCanvas::setPenColor(const char* color) {
if (currentPen != 0) {
currentPen->setColor(getColor(color));
}
}
void RMapCanvas::setPenLineStyle(const char* style) {
if (currentPen != 0) {
if (strcasecmp (style, "dashed") == 0) {
currentPen->setStyle(Qt::DashLine);
} else {
currentPen->setStyle(Qt::SolidLine);
}
}
}
void RMapCanvas::setPenThickness(int thickness) {
if (currentPen != 0) {
currentPen->setWidth(thickness);
}
}
void RMapCanvas::erase() {
if (pixmap) {
pixmap->fill(currentPen->color());
}
}
void RMapCanvas::getTextExtents(const char* text, int* w, int* ascent,
int* descent, int *can_tilt) {
QFont f("Arial Bold",12);
QFontMetrics fm(f);
QRect r = fm.boundingRect(QString::fromUtf8(text));
*w = r.width();
*ascent = fm.ascent();
*descent = fm.descent();
#ifdef QT_NO_ROTATE
if (can_tilt) *can_tilt = 0;
#else
if (can_tilt) *can_tilt = 1;
#endif
}
void RMapCanvas::drawString(RoadMapGuiPoint* position,
int corner, const char* text) {
if (!pixmap) {
return;
}
QPainter p(pixmap);
if (currentPen != 0) {
p.setPen(*currentPen);
}
QFont f("Arial Bold",12);
p.setFont(f);
int text_width;
int text_ascent;
int text_descent;
int x, y;
getTextExtents(text, &text_width, &text_ascent, &text_descent, NULL);
x = position->x;
y = position->y;
if (corner & ROADMAP_CANVAS_RIGHT)
x -= text_width;
else if (corner & ROADMAP_CANVAS_CENTER_X)
x -= text_width / 2;
if (corner & ROADMAP_CANVAS_BOTTOM)
y -= text_descent;
else if (corner & ROADMAP_CANVAS_CENTER_Y)
y = y - text_descent + ((text_descent + text_ascent) / 2);
else /* TOP */
y += text_ascent;
p.drawText(x, y, QString::fromUtf8(text));
}
void RMapCanvas::drawStringAngle(RoadMapGuiPoint* position,
int center, const char* text, int angle) {
#ifndef QT_NO_ROTATE
if (!pixmap) {
return;
}
QPainter p(pixmap);
if (currentPen != 0) {
p.setPen(*currentPen);
}
QFont f("Arial Bold",12);
int text_width;
int text_ascent;
int text_descent;
getTextExtents(text, &text_width, &text_ascent, &text_descent, NULL);
p.setFont(f);
p.translate(position->x,position->y);
p.rotate((double)angle);
p.drawText(0, -text_descent, QString::fromUtf8(text));
#endif
}
void RMapCanvas::drawMultiplePoints(int count, RoadMapGuiPoint* points) {
QPainter p(pixmap);
if (currentPen != 0) {
p.setPen(*currentPen);
}
QPolygon pa(count);
for(int n = 0; n < count; n++) {
pa.setPoint(n, points[n].x, points[n].y);
}
p.drawPoints(pa);
}
void RMapCanvas::drawMultipleLines(int count, int* lines, RoadMapGuiPoint* points) {
QPainter p(pixmap);
if (currentPen != 0) {
p.setPen(*currentPen);
}
for(int i = 0; i < count; i++) {
int count_of_points = *lines;
QPolygon pa(count_of_points);
for(int n = 0; n < count_of_points; n++) {
pa.setPoint(n, points[n].x, points[n].y);
}
p.drawPolyline(pa);
lines++;
points += count_of_points;
}
}
void RMapCanvas::drawMultiplePolygons(int count, int* polygons,
RoadMapGuiPoint* points, int filled) {
QPainter p(pixmap);
if (currentPen != 0) {
if (filled) {
p.setPen(/* *currentPen*/ QPen(Qt::NoPen));
p.setBrush(QBrush(currentPen->color()));
} else {
p.setPen(*currentPen);
}
}
for(int i = 0; i < count; i++) {
int count_of_points = *polygons;
QPolygon pa(count_of_points);
for(int n = 0; n < count_of_points; n++) {
pa.setPoint(n, points[n].x, points[n].y);
}
p.drawPolygon(pa);
polygons++;
points += count_of_points;
}
}
void RMapCanvas::drawMultipleCircles(int count, RoadMapGuiPoint* centers,
int* radius, int filled) {
QPainter p(pixmap);
if (currentPen != 0) {
if (filled) {
p.setPen(*currentPen);
p.setBrush(QBrush(currentPen->color()));
} else {
p.setPen(*currentPen);
}
}
for(int i = 0; i < count; i++) {
int r = radius[i];
p.drawEllipse(centers[i].x - r, centers[i].y - r, 2*r, 2*r);
if (filled) {
p.drawChord(centers[i].x - r + 1,
centers[i].y - r + 1,
2 * r, 2 * r, 0, 16*360);
}
}
}
void RMapCanvas::registerButtonPressedHandler(RoadMapCanvasMouseHandler handler) {
buttonPressedHandler = handler;
}
void RMapCanvas::registerButtonReleasedHandler(RoadMapCanvasMouseHandler handler) {
buttonReleasedHandler = handler;
}
void RMapCanvas::registerMouseMoveHandler(RoadMapCanvasMouseHandler handler) {
mouseMoveHandler = handler;
}
void RMapCanvas::registerMouseWheelHandler(RoadMapCanvasMouseHandler handler) {
mouseWheelHandler = handler;
}
void RMapCanvas::registerConfigureHandler(RoadMapCanvasConfigureHandler handler) {
configureHandler = handler;
}
int RMapCanvas::getHeight() {
return height();
}
int RMapCanvas::getWidth() {
return width();
}
void RMapCanvas::refresh(void) {
update();
}
void RMapCanvas::mousePressEvent(QMouseEvent* ev) {
int button;
RoadMapGuiPoint pt;
switch (ev->button()) {
case Qt::LeftButton: button = 1; break;
case Qt::MidButton: button = 2; break;
case Qt::RightButton: button = 3; break;
default: button = 0; break;
}
pt.x = ev->x();
pt.y = ev->y();
if (buttonPressedHandler != 0) {
buttonPressedHandler(button, &pt);
}
}
void RMapCanvas::mouseReleaseEvent(QMouseEvent* ev) {
int button;
RoadMapGuiPoint pt;
switch (ev->button()) {
case Qt::LeftButton: button = 1; break;
case Qt::MidButton: button = 2; break;
case Qt::RightButton: button = 3; break;
default: button = 0; break;
}
pt.x = ev->x();
pt.y = ev->y();
if (buttonReleasedHandler != 0) {
buttonReleasedHandler(button, &pt);
}
}
void RMapCanvas::mouseMoveEvent(QMouseEvent* ev) {
RoadMapGuiPoint pt;
pt.x = ev->x();
pt.y = ev->y();
if (mouseMoveHandler != 0) {
mouseMoveHandler(0, &pt);
}
}
void RMapCanvas::wheelEvent (QWheelEvent* ev) {
int direction;
RoadMapGuiPoint pt;
pt.x = ev->x();
pt.y = ev->y();
direction = ev->delta();
direction = (direction > 0) ? 1 : ((direction < 0) ? -1 : 0);
if (mouseWheelHandler != 0) {
mouseWheelHandler(direction, &pt);
}
}
void RMapCanvas::resizeEvent(QResizeEvent* ev) {
configure();
}
void RMapCanvas::paintEvent(QPaintEvent* ev) {
QRect target(0, 0, pixmap->width(), pixmap->height());
QRect source(0, 0, pixmap->width(), pixmap->height());
QPainter painter(this);
painter.drawPixmap( target, *pixmap, source);
//bitBlt(this, QPoint(0,0), pixmap, QRect(0, 0, pixmap->width(), pixmap->height()));
}
void RMapCanvas::configure() {
if (pixmap != 0) {
delete pixmap;
}
pixmap = new QPixmap(width(), height());
if (configureHandler != 0) {
configureHandler();
}
}
QColor RMapCanvas::getColor(const char* color) {
QColor *c = colors[color];
if (c == 0) {
c = new QColor(color);
colors.insert(color, c);
}
return *c;
}
void RMapCanvas::initColors() {
#ifdef QWS
// It seems that QPE does not have predefined named colors.
// Temporary fix is to hard-code some. Better solution
// is to read rgb.txt??
colors.insert("black", new QColor(0, 0, 0));
colors.insert("blue", new QColor(0, 0, 255));
colors.insert("DarkGrey", new QColor(169, 169, 169));
colors.insert("green", new QColor(0, 255, 0));
colors.insert("grey", new QColor(190, 190, 190));
colors.insert("IndianRed", new QColor(205, 92, 92));
colors.insert("LightBlue", new QColor(173, 216, 230));
colors.insert("LightSlateBlue", new QColor(132, 112, 255));
colors.insert("LightYellow", new QColor(255, 255, 224));
colors.insert("red", new QColor(255, 0, 0));
colors.insert("white", new QColor(255, 255, 255));
colors.insert("yellow", new QColor(255, 255, 0));
colors.insert("DarkSeaGreen4", new QColor(105, 139, 105));
#endif
#ifdef QT4
colors.insert("LightSlateBlue", new QColor(132, 112, 255));
colors.insert("DarkSeaGreen4", new QColor(105, 139, 105));
#endif
}
--- NEW FILE: roadmap_main.cc ---
/* roadmap_main.cc - A C to C++ wrapper for the QT RoadMap main function.
*
* LICENSE:
*
* (c) Copyright 2003 Latchesar Ionkov
*
* This file is part of RoadMap.
*
* RoadMap 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.
*
* RoadMap 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 RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* SYNOPSYS:
*
* See roadmap_main.h
*/
extern "C" {
#include <stdlib.h>
#include <sys/time.h>
#include "roadmap.h"
#include "roadmap_start.h"
#include "roadmap_config.h"
#include "roadmap_history.h"
#include "roadmap_main.h"
};
#ifdef QWS
#include <qapplication.h>
#else
#include <qapplication.h>
#endif
#include "qt_main.h"
#ifdef QWS
static QApplication* app;
#else
static QApplication* app;
#endif
RMapMainWindow* mainWindow;
struct roadmap_main_io {
RoadMapIO io;
RoadMapInput callback;
};
#define ROADMAP_MAX_IO 16
static struct roadmap_main_io RoadMapMainIo[ROADMAP_MAX_IO];
static void roadmap_main_input (int fd) {
int i;
for (i = 0; i < ROADMAP_MAX_IO; ++i) {
if (RoadMapMainIo[i].io.os.file == fd) {
(*RoadMapMainIo[i].callback) (&RoadMapMainIo[i].io);
break;
}
}
}
void roadmap_main_new(const char* title, int width, int height) {
mainWindow = new RMapMainWindow(0,0);
#ifdef QWS
//app->showMainWidget(mainWindow);
#else
//app->setMainWidget(mainWindow);
#endif
mainWindow->setWindowTitle(title);
mainWindow->resize(width,height);
mainWindow->show();
}
void roadmap_main_title(char *fmt, ...) {
/* unimplemented */
}
void roadmap_main_set_keyboard(RoadMapKeyInput callback) {
if (mainWindow) {
mainWindow->setKeyboardCallback(callback);
}
}
RoadMapMenu roadmap_main_new_menu (const char *title) {
if (mainWindow) {
return (RoadMapMenu) mainWindow->newMenu(title);
} else {
return (RoadMapMenu) NULL;
}
}
void roadmap_main_free_menu (RoadMapMenu menu) {
if (mainWindow) {
mainWindow->freeMenu((QMenu *)menu);
}
}
void roadmap_main_popup_menu (RoadMapMenu menu,
const RoadMapGuiPoint *position) {
//tsdogs ????
if (mainWindow) {
mainWindow->popupMenu((QMenu *)menu, position->x, position->y);
}
}
void roadmap_main_add_menu(RoadMapMenu menu, const char* label) {
if (mainWindow) {
mainWindow->addMenu((QMenu *)menu, label);
}
}
void roadmap_main_add_menu_item(RoadMapMenu menu,
const char* label,
const char* tip,
RoadMapCallback callback) {
if (mainWindow) {
mainWindow->addMenuItem((QMenu *)menu, label, tip, callback);
}
}
void roadmap_main_add_separator(RoadMapMenu menu) {
if (mainWindow) {
mainWindow->addMenuSeparator((QMenu *)menu);
}
}
void roadmap_main_add_toolbar (const char *orientation) {
if (mainWindow) {
mainWindow->addToolbar(orientation);
}
}
void roadmap_main_add_tool(const char* label,
const char *icon,
const char* tip,
RoadMapCallback callback) {
if (mainWindow) {
mainWindow->addTool(label, icon, tip, callback);
}
}
void roadmap_main_add_tool_space(void) {
if (mainWindow) {
mainWindow->addToolSpace();
}
}
void roadmap_main_add_canvas(void) {
// The canvas is implicitely added to the main window.
// if (mainWindow) {
// mainWindow->addCanvas();
// }
}
void roadmap_main_add_status(void) {
// nothing to be done
}
void roadmap_main_show(void) {
if (mainWindow) {
mainWindow->show();
}
}
void roadmap_main_set_input(RoadMapIO *io, RoadMapInput callback) {
if (mainWindow) {
int i;
/* All the same on UNIX. */
mainWindow->addInput(io->os.file, roadmap_main_input);
for (i = 0; i < ROADMAP_MAX_IO; ++i) {
if (RoadMapMainIo[i].io.subsystem == ROADMAP_IO_INVALID) {
RoadMapMainIo[i].io = *io;
RoadMapMainIo[i].callback = callback;
break;
}
}
}
}
void roadmap_main_remove_input(RoadMapIO *io) {
int i;
int fd = io->os.file; /* All the same on UNIX. */
if (mainWindow) {
mainWindow->removeInput(fd);
}
for (i = 0; i < ROADMAP_MAX_IO; ++i) {
if (RoadMapMainIo[i].io.os.file == fd) {
RoadMapMainIo[i].io.subsystem = ROADMAP_IO_INVALID;
RoadMapMainIo[i].io.os.file = -1;
break;
}
}
}
void roadmap_main_set_periodic (int interval, RoadMapCallback callback) {
if (mainWindow) {
mainWindow->setTimer(interval, callback);
}
}
void roadmap_main_remove_periodic (RoadMapCallback callback) {
if (mainWindow) {
mainWindow->removeTimer(callback);
}
}
void roadmap_main_set_status(const char *text) {
if (mainWindow) {
mainWindow->setStatus(text);
}
}
void roadmap_main_toggle_full_screen (void) {
// Not yet implemented (how to do this ??)
}
void roadmap_main_flush (void) {
if (app != NULL) {
app->processEvents ();
}
}
int roadmap_main_flush_synchronous (int deadline) {
if (app != NULL) {
long start_time, end_time, duration;
struct timeval now;
gettimeofday(&now, 0);
start_time = (now.tv_sec % 100000) * 1000 + now.tv_usec / 1000;
app->processEvents ();
app->syncX();
gettimeofday(&now, 0);
end_time = (now.tv_sec % 100000) * 1000 + now.tv_usec / 1000;
duration = end_time - start_time;
if (duration > deadline) {
roadmap_log (ROADMAP_DEBUG, "processing flush took %d", duration);
return 0; /* Busy. */
}
}
return 1;
}
void roadmap_main_exit(void) {
roadmap_start_exit();
exit(0);
}
int main(int argc, char* argv[]) {
int i;
#ifdef QWS
app = new QApplication(argc, argv);
#else
app = new QApplication(argc, argv);
#endif
for (i = 0; i < ROADMAP_MAX_IO; ++i) {
RoadMapMainIo[i].io.subsystem = ROADMAP_IO_INVALID;
RoadMapMainIo[i].io.os.file = -1;
}
roadmap_start(argc, argv);
return app->exec();
}
|