Browse Source

TQt4 port Abakus

This enables compilation under both Qt3 and Qt4


git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/abakus@1231045 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 10 years ago
parent
commit
f4f8ac034f
36 changed files with 728 additions and 718 deletions
  1. +12
    -11
      bksys/kde.py
  2. +1
    -1
      src/SConscript
  3. +1
    -1
      src/abakus.cpp
  4. +3
    -3
      src/abakuscommon.h
  5. +40
    -40
      src/abakuslistview.cpp
  6. +21
    -18
      src/abakuslistview.h
  7. +2
    -2
      src/dcopIface.h
  8. +23
    -23
      src/dragsupport.cpp
  9. +4
    -4
      src/dragsupport.h
  10. +130
    -130
      src/editor.cpp
  11. +26
    -24
      src/editor.h
  12. +21
    -21
      src/evaluator.cpp
  13. +14
    -14
      src/evaluator.h
  14. +27
    -27
      src/function.cpp
  15. +23
    -22
      src/function.h
  16. +4
    -4
      src/hmath.cpp
  17. +2
    -2
      src/hmath.h
  18. +2
    -2
      src/lexer.ll
  19. +131
    -131
      src/mainwindow.cpp
  20. +28
    -27
      src/mainwindow.h
  21. +13
    -13
      src/node.cpp
  22. +14
    -14
      src/node.h
  23. +2
    -2
      src/number.c
  24. +20
    -20
      src/numerictypes.cpp
  25. +8
    -8
      src/numerictypes.h
  26. +20
    -20
      src/parser.yy
  27. +1
    -1
      src/result.cpp
  28. +4
    -4
      src/result.h
  29. +23
    -23
      src/resultlistview.cpp
  30. +9
    -8
      src/resultlistview.h
  31. +24
    -24
      src/resultlistviewtext.cpp
  32. +12
    -12
      src/resultlistviewtext.h
  33. +19
    -19
      src/rpnmuncher.cpp
  34. +6
    -6
      src/rpnmuncher.h
  35. +20
    -20
      src/valuemanager.cpp
  36. +18
    -17
      src/valuemanager.h

+ 12
- 11
bksys/kde.py View File

@ -166,25 +166,26 @@ def detect_kde(env):
env.Exit(1)
env['QT_MOC'] = moc
## check for the tqt and kde includes
print "Checking for the tqt includes : ",
if qtincludes and os.path.isfile(qtincludes + "/tqt.h"):
## check for the qt and kde includes
print "Checking for the qt includes : ",
if qtincludes and os.path.isfile(qtincludes + "/qlayout.h"):
# The user told where to look for and it looks valid
print GREEN + "ok " + qtincludes + NORMAL
else:
if os.path.isfile(qtdir + "/include/tqt.h"):
if os.path.isfile(qtdir + "/include/qlayout.h"):
# Automatic detection
print GREEN + "ok " + qtdir + "/include/ " + NORMAL
qtincludes = qtdir + "/include/"
elif os.path.isfile("/usr/include/tqt.h"):
print YELLOW + "the tqt headers were found in /usr/include/ " + NORMAL
qtincludes = "/usr/include"
elif os.path.isfile("/usr/include/tqt/tqt.h"):
elif os.path.isfile("/usr/include/qt3/qlayout.h"):
# Debian probably
print YELLOW + "the tqt headers were found in /usr/include/tqt/ " + NORMAL
qtincludes = "/usr/include/tqt"
print YELLOW + "the qt headers were found in /usr/include/qt3/ " + NORMAL
qtincludes = "/usr/include/qt3"
elif os.path.isfile("/usr/include/qt4/Qt/qglobal.h"):
# Debian probably
print YELLOW + "the qt headers were found in /usr/include/qt4/ " + NORMAL
qtincludes = "/usr/include/qt4"
else:
print RED + "the tqt headers were not found" + NORMAL
print RED + "the qt headers were not found" + NORMAL
env.Exit(1)
print "Checking for the kde includes : ",


+ 1
- 1
src/SConscript View File

@ -66,7 +66,7 @@ myenv.Append(CXXFLAGS = '-Wno-non-virtual-dtor -I/usr/include/tqt -include tqt.h
myenv.KDEaddpaths_includes('#/src/ #/')
## Necessary libraries to link against
myenv.KDEaddlibs( 'qt-mt kio kdecore kdeprint kdeui' )
myenv.KDEaddlibs( 'kio kdecore kdeprint kdeui' )
#############################
## Data to install


+ 1
- 1
src/abakus.cpp View File

@ -66,7 +66,7 @@ int main(int argc, char **argv)
MainWindow *win = new MainWindow;
app.setMainWidget(win);
app.connect(&app, SIGNAL(lastWindowClosed()), SLOT(quit()));
app.connect(&app, TQT_SIGNAL(lastWindowClosed()), TQT_SLOT(quit()));
win->show();
win->resize(500, 300);


+ 3
- 3
src/abakuscommon.h View File

@ -11,9 +11,9 @@
#include <kpopupmenu.h>
#include <kaction.h>
#include <qlabel.h>
#include <qregexp.h>
#include <qtimer.h>
#include <tqlabel.h>
#include <tqregexp.h>
#include <tqtimer.h>
#include "function.h"
#include "node.h"


+ 40
- 40
src/abakuslistview.cpp View File

@ -20,38 +20,38 @@
#include <kpopupmenu.h>
#include <kdebug.h>
#include <qdragobject.h>
#include <qcursor.h>
#include <qheader.h>
#include <tqdragobject.h>
#include <tqcursor.h>
#include <tqheader.h>
#include "dragsupport.h"
#include "abakuslistview.h"
#include "valuemanager.h"
#include "function.h"
ListView::ListView(QWidget *parent, const char *name) :
KListView(parent, name), m_menu(0), m_usePopup(false), m_removeSingleId(0),
ListView::ListView(TQWidget *tqparent, const char *name) :
KListView(tqparent, name), m_menu(0), m_usePopup(false), m_removeSingleId(0),
m_removeAllId(0)
{
setResizeMode(LastColumn);
setDragEnabled(true);
connect(this, SIGNAL(contextMenuRequested(QListViewItem *, const QPoint &, int)),
SLOT(rightClicked(QListViewItem *, const QPoint &)));
connect(this, TQT_SIGNAL(contextMenuRequested(TQListViewItem *, const TQPoint &, int)),
TQT_SLOT(rightClicked(TQListViewItem *, const TQPoint &)));
}
QDragObject *ListView::dragObject()
TQDragObject *ListView::dragObject()
{
QPoint viewportPos = viewport()->mapFromGlobal(QCursor::pos());
QListViewItem *item = itemAt(viewportPos);
TQPoint viewportPos = viewport()->mapFromGlobal(TQCursor::pos());
TQListViewItem *item = itemAt(viewportPos);
if(!item)
return 0;
int column = header()->sectionAt(viewportPos.x());
QString dragText = item->text(column);
TQString dragText = item->text(column);
QDragObject *drag = new QTextDrag(dragText, this, "list item drag");
TQDragObject *drag = new TQTextDrag(dragText, this, "list item drag");
drag->setPixmap(DragSupport::makePixmap(dragText, font()));
return drag;
@ -70,8 +70,8 @@ void ListView::enablePopupHandler(bool enable)
m_menu = new KPopupMenu(this);
m_removeSingleId = m_menu->insertItem(removeItemString(), this, SLOT(removeSelected()));
m_removeAllId = m_menu->insertItem("Placeholder", this, SLOT(removeAllItems()));
m_removeSingleId = m_menu->insertItem(removeItemString(), this, TQT_SLOT(removeSelected()));
m_removeAllId = m_menu->insertItem("Placeholder", this, TQT_SLOT(removeAllItems()));
}
else {
delete m_menu;
@ -79,19 +79,19 @@ void ListView::enablePopupHandler(bool enable)
}
}
QString ListView::removeItemString() const
TQString ListView::removeItemString() const
{
return QString();
return TQString();
}
QString ListView::removeAllItemsString(unsigned count) const
TQString ListView::removeAllItemsString(unsigned count) const
{
Q_UNUSED(count);
return QString();
return TQString();
}
void ListView::removeSelectedItem(QListViewItem *item)
void ListView::removeSelectedItem(TQListViewItem *item)
{
Q_UNUSED(item);
}
@ -100,14 +100,14 @@ void ListView::removeAllItems()
{
}
bool ListView::isItemRemovable(QListViewItem *item) const
bool ListView::isItemRemovable(TQListViewItem *item) const
{
Q_UNUSED(item);
return false;
}
void ListView::rightClicked(QListViewItem *item, const QPoint &pt)
void ListView::rightClicked(TQListViewItem *item, const TQPoint &pt)
{
if(!m_usePopup)
return;
@ -122,7 +122,7 @@ void ListView::removeSelected()
removeSelectedItem(selectedItem());
}
ValueListViewItem::ValueListViewItem(QListView *listView, const QString &name,
ValueListViewItem::ValueListViewItem(TQListView *listView, const TQString &name,
const Abakus::number_t &value) :
KListViewItem(listView, name), m_value(value)
{
@ -132,7 +132,7 @@ ValueListViewItem::ValueListViewItem(QListView *listView, const QString &name,
void ValueListViewItem::valueChanged()
{
setText(1, m_value.toString());
repaint();
tqrepaint();
}
void ValueListViewItem::valueChanged(const Abakus::number_t &newValue)
@ -147,25 +147,25 @@ Abakus::number_t ValueListViewItem::itemValue() const
return m_value;
}
VariableListView::VariableListView(QWidget *parent, const char *name) :
ListView(parent, name)
VariableListView::VariableListView(TQWidget *tqparent, const char *name) :
ListView(tqparent, name)
{
enablePopupHandler(true);
}
QString VariableListView::removeItemString() const
TQString VariableListView::removeItemString() const
{
return i18n("Remove selected variable");
}
QString VariableListView::removeAllItemsString(unsigned count) const
TQString VariableListView::removeAllItemsString(unsigned count) const
{
// count is unreliable because not all of the elements in the list view
// can be removed.
count = 0;
QStringList values = ValueManager::instance()->valueNames();
TQStringList values = ValueManager::instance()->valueNames();
for(QStringList::ConstIterator value = values.constBegin(); value != values.constEnd(); ++value)
for(TQStringList::ConstIterator value = values.constBegin(); value != values.constEnd(); ++value)
if(!ValueManager::instance()->isValueReadOnly(*value))
++count;
@ -174,12 +174,12 @@ QString VariableListView::removeAllItemsString(unsigned count) const
count);
}
bool VariableListView::isItemRemovable(QListViewItem *item) const
bool VariableListView::isItemRemovable(TQListViewItem *item) const
{
return !ValueManager::instance()->isValueReadOnly(item->text(0));
}
void VariableListView::removeSelectedItem(QListViewItem *item)
void VariableListView::removeSelectedItem(TQListViewItem *item)
{
ValueManager::instance()->removeValue(item->text(0));
}
@ -189,43 +189,43 @@ void VariableListView::removeAllItems()
ValueManager::instance()->slotRemoveUserVariables();
}
FunctionListView::FunctionListView(QWidget *parent, const char *name) :
ListView(parent, name)
FunctionListView::FunctionListView(TQWidget *tqparent, const char *name) :
ListView(tqparent, name)
{
enablePopupHandler(true);
}
QString FunctionListView::removeItemString() const
TQString FunctionListView::removeItemString() const
{
return i18n("Remove selected function");
}
QString FunctionListView::removeAllItemsString(unsigned count) const
TQString FunctionListView::removeAllItemsString(unsigned count) const
{
return i18n("Remove all functions (1 function)",
"Remove all functions (%n functions)",
count);
}
bool FunctionListView::isItemRemovable(QListViewItem *item) const
bool FunctionListView::isItemRemovable(TQListViewItem *item) const
{
return true;
}
void FunctionListView::removeSelectedItem(QListViewItem *item)
void FunctionListView::removeSelectedItem(TQListViewItem *item)
{
// Use section to get the beginning of the string up to (and not
// including) the first (
QString name = item->text(0).section('(', 0, 0);
TQString name = item->text(0).section('(', 0, 0);
FunctionManager::instance()->removeFunction(name);
}
void FunctionListView::removeAllItems()
{
QStringList fns = FunctionManager::instance()->functionList(FunctionManager::UserDefined);
TQStringList fns = FunctionManager::instance()->functionList(FunctionManager::UserDefined);
for(QStringList::ConstIterator fn = fns.constBegin(); fn != fns.constEnd(); ++fn)
for(TQStringList::ConstIterator fn = fns.constBegin(); fn != fns.constEnd(); ++fn)
FunctionManager::instance()->removeFunction(*fn);
}


+ 21
- 18
src/abakuslistview.h View File

@ -28,12 +28,13 @@ class KPopupMenu;
class ListView : public KListView
{
Q_OBJECT
TQ_OBJECT
public:
ListView(QWidget *parent, const char *name = 0);
ListView(TQWidget *tqparent, const char *name = 0);
protected:
virtual QDragObject *dragObject();
virtual TQDragObject *dragObject();
/**
* Used to enable fancy popup handling support in subclasses. Subclasses
@ -47,7 +48,7 @@ class ListView : public KListView
* If using the popup menu handling, the subclass needs to return a
* translated string of the form "Remove selected <itemtype>".
*/
virtual QString removeItemString() const;
virtual TQString removeItemString() const;
/**
* If using the popup menu handling, the subclass needs to return a
@ -55,7 +56,7 @@ class ListView : public KListView
* also appending a " (%n <itemtype>s), which you can use the @p count
* parameter for.
*/
virtual QString removeAllItemsString(unsigned count) const;
virtual TQString removeAllItemsString(unsigned count) const;
protected slots:
/**
@ -63,7 +64,7 @@ class ListView : public KListView
* function to remove the selected item, which is passed in as a
* parameter.
*/
virtual void removeSelectedItem(QListViewItem *item);
virtual void removeSelectedItem(TQListViewItem *item);
/**
* If using the popup menu handling, the subclass needs to reimplement this
@ -75,10 +76,10 @@ class ListView : public KListView
* If using the popup menu handling, this function may be called to
* determine whether the selected item given by @p item is removable.
*/
virtual bool isItemRemovable(QListViewItem *item) const;
virtual bool isItemRemovable(TQListViewItem *item) const;
private slots:
void rightClicked(QListViewItem *item, const QPoint &pt);
void rightClicked(TQListViewItem *item, const TQPoint &pt);
void removeSelected();
private:
@ -92,7 +93,7 @@ class ListView : public KListView
class ValueListViewItem : public KListViewItem
{
public:
ValueListViewItem (QListView *listView, const QString &name, const Abakus::number_t &value);
ValueListViewItem (TQListView *listView, const TQString &name, const Abakus::number_t &value);
// Will cause the list item to rethink the text.
void valueChanged();
@ -110,17 +111,18 @@ class ValueListViewItem : public KListViewItem
class VariableListView : public ListView
{
Q_OBJECT
TQ_OBJECT
public:
VariableListView(QWidget *parent, const char *name = 0);
VariableListView(TQWidget *tqparent, const char *name = 0);
protected:
virtual QString removeItemString() const;
virtual QString removeAllItemsString(unsigned count) const;
virtual bool isItemRemovable(QListViewItem *item) const;
virtual TQString removeItemString() const;
virtual TQString removeAllItemsString(unsigned count) const;
virtual bool isItemRemovable(TQListViewItem *item) const;
protected slots:
virtual void removeSelectedItem(QListViewItem *item);
virtual void removeSelectedItem(TQListViewItem *item);
virtual void removeAllItems();
};
@ -130,17 +132,18 @@ class VariableListView : public ListView
class FunctionListView : public ListView
{
Q_OBJECT
TQ_OBJECT
public:
FunctionListView(QWidget *parent, const char *name = 0);
FunctionListView(TQWidget *tqparent, const char *name = 0);
protected:
virtual QString removeItemString() const;
virtual QString removeAllItemsString(unsigned count) const;
virtual bool isItemRemovable(QListViewItem *item) const;
virtual TQString removeItemString() const;
virtual TQString removeAllItemsString(unsigned count) const;
virtual bool isItemRemovable(TQListViewItem *item) const;
protected slots:
virtual void removeSelectedItem(QListViewItem *item);
virtual void removeSelectedItem(TQListViewItem *item);
virtual void removeAllItems();
};


+ 2
- 2
src/dcopIface.h View File

@ -22,7 +22,7 @@
#include <kdebug.h>
#include <dcopobject.h>
#include <qstring.h>
#include <tqstring.h>
#include "mainwindow.h"
#include "numerictypes.h"
@ -37,7 +37,7 @@ class AbakusIface : virtual public DCOPObject
}
k_dcop:
virtual double evaluate(const QString &expr)
virtual double evaluate(const TQString &expr)
{
Abakus::number_t result = parseString(expr.latin1());
return result.asDouble();


+ 23
- 23
src/dragsupport.cpp View File

@ -17,42 +17,42 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <qstring.h>
#include <qpixmap.h>
#include <qimage.h>
#include <qpainter.h>
#include <qcolor.h>
#include <qfont.h>
#include <qbrush.h>
#include <qfontmetrics.h>
#include <tqstring.h>
#include <tqpixmap.h>
#include <tqimage.h>
#include <tqpainter.h>
#include <tqcolor.h>
#include <tqfont.h>
#include <tqbrush.h>
#include <tqfontmetrics.h>
#include "dragsupport.h"
namespace DragSupport
{
QPixmap makePixmap(const QString &text, const QFont &font)
TQPixmap makePixmap(const TQString &text, const TQFont &font)
{
QColor background(234, 178, 230);
QFontMetrics fm(font);
TQColor background(234, 178, 230);
TQFontMetrics fm(font);
int height = 2 * fm.height();
QSize bonusSize (height, 0);
QSize size(fm.width(text), height);
QImage image(size + bonusSize, 32);
TQSize bonusSize (height, 0);
TQSize size(fm.width(text), height);
TQImage image(size + bonusSize, 32);
image.setAlphaBuffer(false);
image.fill(0); // All transparent pixels
image.setAlphaBuffer(true);
QPixmap pix(size + bonusSize);
pix.fill(Qt::magenta); // Watch for incoming hacks
TQPixmap pix(size + bonusSize);
pix.fill(TQt::magenta); // Watch for incoming hacks
QPainter painter(&pix);
TQPainter painter(&pix);
painter.setFont(font);
// Outline black, background white
painter.setPen(Qt::black);
painter.setPen(TQt::black);
painter.setBrush(background);
// roundRect is annoying in that the four "pies" in each corner aren't
@ -64,19 +64,19 @@ QPixmap makePixmap(const QString &text, const QFont &font)
int textLeft = height / 2;
// Draw text
painter.setPen(Qt::black);
painter.setPen(TQt::black);
painter.drawText(textLeft, height / 4, size.width(), size.height(), 0, text);
QImage overlay(pix.convertToImage());
TQImage overlay(pix.convertToImage());
// The images should have the same size, copy pixels from overlay to the
// bottom unless the pixel is called magenta. The pixels we don't copy
// are transparent in the QImage, and will remain transparent when
// converted to a QPixmap.
// are transparent in the TQImage, and will remain transparent when
// converted to a TQPixmap.
for(int i = 0; i < image.width(); ++i)
for(int j = 0; j < image.height(); ++j) {
if(QColor(overlay.pixel(i, j)) != Qt::magenta)
if(TQColor(overlay.pixel(i, j)) != TQt::magenta)
image.setPixel(i, j, overlay.pixel(i, j));
}


+ 4
- 4
src/dragsupport.h View File

@ -19,13 +19,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
class QPixmap;
class QString;
class QFont;
class TQPixmap;
class TQString;
class TQFont;
namespace DragSupport {
QPixmap makePixmap(const QString &text, const QFont &font);
TQPixmap makePixmap(const TQString &text, const TQFont &font);
}
#endif


+ 130
- 130
src/editor.cpp View File

@ -25,23 +25,23 @@
#include "evaluator.h"
#include "result.h"
#include <qapplication.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qlistbox.h>
#include <qpainter.h>
#include <qregexp.h>
#include <qstringlist.h>
#include <qstyle.h>
#include <qsyntaxhighlighter.h>
#include <qtimer.h>
#include <qtooltip.h>
#include <qmessagebox.h>
#include <qvbox.h>
#include <tqapplication.h>
#include <tqlabel.h>
#include <tqlineedit.h>
#include <tqlistbox.h>
#include <tqpainter.h>
#include <tqregexp.h>
#include <tqstringlist.h>
#include <tqstyle.h>
#include <tqsyntaxhighlighter.h>
#include <tqtimer.h>
#include <tqtooltip.h>
#include <tqmessagebox.h>
#include <tqvbox.h>
#include <netwm.h>
#include <fixx11h.h> // netwm.h includes X11 headers which conflict with qevent
#include <qevent.h>
#include <tqevent.h>
#include <kdebug.h>
@ -50,26 +50,26 @@
// XXX: QT 4: Replace this with qBinaryFind().
using std::binary_search;
class CalcResultLabel : public QLabel
class CalcResultLabel : public TQLabel
{
public:
CalcResultLabel(QWidget *parent, const char *name, int WFlags) :
QLabel(parent, name, WFlags)
CalcResultLabel(TQWidget *tqparent, const char *name, int WFlags) :
TQLabel(tqparent, name, WFlags)
{
}
protected:
virtual void mousePressEvent(QMouseEvent *)
virtual void mousePressEvent(TQMouseEvent *)
{
hide();
}
};
class EditorHighlighter : public QSyntaxHighlighter
class EditorHighlighter : public TQSyntaxHighlighter
{
public:
EditorHighlighter( Editor* );
int highlightParagraph ( const QString & text, int );
int highlightParagraph ( const TQString & text, int );
private:
Editor* editor;
@ -79,50 +79,50 @@ class Editor::Private
{
public:
Evaluator* eval;
QStringList history;
TQStringList history;
int index;
bool autoCompleteEnabled;
EditorCompletion* completion;
QTimer* completionTimer;
TQTimer* completionTimer;
bool autoCalcEnabled;
char format;
int decimalDigits;
QTimer* autoCalcTimer;
QLabel* autoCalcLabel;
TQTimer* autoCalcTimer;
TQLabel* autoCalcLabel;
bool syntaxHighlightEnabled;
EditorHighlighter* highlighter;
QMap<ColorType,QColor> highlightColors;
QTimer* matchingTimer;
TQMap<ColorType,TQColor> highlightColors;
TQTimer* matchingTimer;
};
class EditorCompletion::Private
{
public:
Editor* editor;
QVBox *completionPopup;
QListBox *completionListBox;
TQVBox *completionPopup;
TQListBox *completionListBox;
};
class ChoiceItem: public QListBoxText
class ChoiceItem: public TQListBoxText
{
public:
ChoiceItem( QListBox*, const QString& );
ChoiceItem( TQListBox*, const TQString& );
void setMinNameWidth (int w) { minNameWidth = w; }
int nameWidth() const;
protected:
void paint( QPainter* p );
void paint( TQPainter* p );
private:
QString item;
QString desc;
TQString item;
TQString desc;
int minNameWidth;
};
ChoiceItem::ChoiceItem( QListBox* listBox, const QString& text ):
QListBoxText( listBox, text ), minNameWidth(0)
ChoiceItem::ChoiceItem( TQListBox* listBox, const TQString& text ):
TQListBoxText( listBox, text ), minNameWidth(0)
{
QStringList list = QStringList::split( ':', text );
TQStringList list = TQStringList::split( ':', text );
if( list.count() ) item = list[0];
if( list.count()>1 ) desc = list[1];
}
@ -133,48 +133,48 @@ int ChoiceItem::nameWidth() const
if(item.isEmpty())
return 0;
QFontMetrics fm = listBox()->fontMetrics();
TQFontMetrics fm = listBox()->fontMetrics();
return fm.width( item );
}
void ChoiceItem::paint( QPainter* painter )
void ChoiceItem::paint( TQPainter* painter )
{
int itemHeight = height( listBox() );
QFontMetrics fm = painter->fontMetrics();
TQFontMetrics fm = painter->fontMetrics();
int yPos = ( ( itemHeight - fm.height() ) / 2 ) + fm.ascent();
painter->drawText( 3, yPos, item );
//int xPos = fm.width( item );
int xPos = QMAX(fm.width(item), minNameWidth);
int xPos = TQMAX(fm.width(item), minNameWidth);
if( !isSelected() )
painter->setPen( listBox()->palette().disabled().text().dark() );
painter->setPen( listBox()->tqpalette().disabled().text().dark() );
painter->drawText( 10 + xPos, yPos, desc );
}
EditorHighlighter::EditorHighlighter( Editor* e ):
QSyntaxHighlighter( e )
TQSyntaxHighlighter( e )
{
editor = e;
}
int EditorHighlighter::highlightParagraph ( const QString & text, int )
int EditorHighlighter::highlightParagraph ( const TQString & text, int )
{
if( !editor->isSyntaxHighlightEnabled() )
{
setFormat( 0, text.length(), editor->colorGroup().text() );
setFormat( 0, text.length(), editor->tqcolorGroup().text() );
return 0;
}
QStringList fnames = FunctionManager::instance()->functionList(FunctionManager::All);
TQStringList fnames = FunctionManager::instance()->functionList(FunctionManager::All);
fnames.sort(); // Sort list so we can bin search it.
Tokens tokens = Evaluator::scan( text );
for( unsigned i = 0; i < tokens.count(); i++ )
{
Token& token = tokens[i];
QString text = token.text().lower();
QFont font = editor->font();
QColor color = Qt::black;
TQString text = token.text().lower();
TQFont font = editor->font();
TQColor color = TQt::black;
switch( token.type() )
{
case Token::Number:
@ -204,22 +204,22 @@ int EditorHighlighter::highlightParagraph ( const QString & text, int )
Editor::Editor( QWidget* parent, const char* name ):
QTextEdit( parent, name )
Editor::Editor( TQWidget* tqparent, const char* name ):
TQTextEdit( tqparent, name )
{
d = new Private;
d->eval = 0;
d->index = 0;
d->autoCompleteEnabled = true;
d->completion = new EditorCompletion( this );
d->completionTimer = new QTimer( this );
d->completionTimer = new TQTimer( this );
d->autoCalcEnabled = true;
d->syntaxHighlightEnabled = true;
d->highlighter = new EditorHighlighter( this );
d->autoCalcTimer = new QTimer( this );
d->matchingTimer = new QTimer( this );
d->autoCalcTimer = new TQTimer( this );
d->matchingTimer = new TQTimer( this );
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
tqsetSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed );
setWordWrap( NoWrap );
setHScrollBarMode( AlwaysOff );
setVScrollBarMode( AlwaysOff );
@ -228,26 +228,26 @@ Editor::Editor( QWidget* parent, const char* name ):
setTabChangesFocus( true );
setLinkUnderline( false );
connect( d->completion, SIGNAL( selectedCompletion( const QString& ) ),
SLOT( autoComplete( const QString& ) ) );
connect( this, SIGNAL( textChanged() ), SLOT( checkAutoComplete() ) );
connect( d->completionTimer, SIGNAL( timeout() ), SLOT( triggerAutoComplete() ) );
connect( d->completion, TQT_SIGNAL( selectedCompletion( const TQString& ) ),
TQT_SLOT( autoComplete( const TQString& ) ) );
connect( this, TQT_SIGNAL( textChanged() ), TQT_SLOT( checkAutoComplete() ) );
connect( d->completionTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( triggerAutoComplete() ) );
connect( this, SIGNAL( textChanged() ), SLOT( checkMatching() ) );
connect( d->matchingTimer, SIGNAL( timeout() ), SLOT( doMatchingLeft() ) );
connect( d->matchingTimer, SIGNAL( timeout() ), SLOT( doMatchingRight() ) );
connect( this, SIGNAL( textChanged() ), SLOT( checkAutoCalc() ) );
connect( d->autoCalcTimer, SIGNAL( timeout() ), SLOT( autoCalc() ) );
connect( this, TQT_SIGNAL( textChanged() ), TQT_SLOT( checkMatching() ) );
connect( d->matchingTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( doMatchingLeft() ) );
connect( d->matchingTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( doMatchingRight() ) );
connect( this, TQT_SIGNAL( textChanged() ), TQT_SLOT( checkAutoCalc() ) );
connect( d->autoCalcTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( autoCalc() ) );
d->autoCalcLabel = new CalcResultLabel( 0, "autocalc", WStyle_StaysOnTop |
WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WX11BypassWM );
d->autoCalcLabel->setFrameStyle( QFrame::Plain | QFrame::Box );
d->autoCalcLabel->setPalette( QToolTip::palette() );
d->autoCalcLabel->setFrameStyle( TQFrame::Plain | TQFrame::Box );
d->autoCalcLabel->setPalette( TQToolTip::palette() );
d->autoCalcLabel->hide();
setHighlightColor( Number, QColor(0,0,127) );
setHighlightColor( FunctionName, QColor(85,0,0) );
setHighlightColor( Variable, QColor(0,85,0) );
setHighlightColor( MatchedPar, QColor(255,255,183) );
setHighlightColor( Number, TQColor(0,0,127) );
setHighlightColor( FunctionName, TQColor(85,0,0) );
setHighlightColor( Variable, TQColor(0,85,0) );
setHighlightColor( MatchedPar, TQColor(255,255,183) );
}
Editor::~Editor()
@ -256,24 +256,24 @@ Editor::~Editor()
delete d;
}
QSize Editor::sizeHint() const
TQSize Editor::tqsizeHint() const
{
constPolish();
QFontMetrics fm = fontMetrics();
int h = QMAX(fm.lineSpacing(), 14);
TQFontMetrics fm = fontMetrics();
int h = TQMAX(fm.lineSpacing(), 14);
int w = fm.width( 'x' ) * 20;
int m = frameWidth() * 2;
return( style().sizeFromContents(QStyle::CT_LineEdit, this,
QSize( w + m, h + m + 4 ).
expandedTo(QApplication::globalStrut())));
return( tqstyle().tqsizeFromContents(TQStyle::CT_LineEdit, this,
TQSize( w + m, h + m + 4 ).
expandedTo(TQApplication::globalStrut())));
}
QStringList Editor::history() const
TQStringList Editor::history() const
{
return d->history;
}
void Editor::setHistory( const QStringList& h )
void Editor::setHistory( const TQStringList& h )
{
d->history = h;
d->index = d->history.count();
@ -309,11 +309,11 @@ void Editor::setDecimalDigits( int digits )
d->decimalDigits = digits;
}
void Editor::appendHistory( const QString& text )
void Editor::appendHistory( const TQString& text )
{
if( text.isEmpty() ) return;
QString lastText;
TQString lastText;
if( d->history.count() )
lastText = d->history[ d->history.count()-1 ];
if( text == lastText ) return;
@ -333,9 +333,9 @@ void Editor::squelchNextAutoCalc()
d->autoCalcTimer->stop();
}
void Editor::setText(const QString &txt)
void Editor::setText(const TQString &txt)
{
QTextEdit::setText(txt);
TQTextEdit::setText(txt);
squelchNextAutoCalc();
}
@ -374,7 +374,7 @@ void Editor::doMatchingLeft()
getCursorPosition( &para, &curPos );
// check for right par
QString subtext = text().left( curPos );
TQString subtext = text().left( curPos );
Tokens tokens = Evaluator::scan( subtext );
if( !tokens.valid() ) return;
if( tokens.count()<1 ) return;
@ -423,7 +423,7 @@ void Editor::doMatchingRight()
getCursorPosition( &para, &curPos );
// check for left par
QString subtext = text().right( text().length() - curPos );
TQString subtext = text().right( text().length() - curPos );
Tokens tokens = Evaluator::scan( subtext );
if( !tokens.valid() ) return;
if( tokens.count()<1 ) return;
@ -472,7 +472,7 @@ void Editor::triggerAutoComplete()
// faster now that it uses flex. ;)
int para = 0, curPos = 0;
getCursorPosition( &para, &curPos );
QString subtext = text().left( curPos );
TQString subtext = text().left( curPos );
Tokens tokens = Evaluator::scan( subtext );
if(!tokens.valid())
{
@ -489,18 +489,18 @@ void Editor::triggerAutoComplete()
if( !lastToken.isIdentifier() )
return;
QString id = lastToken.text();
TQString id = lastToken.text();
if( id.isEmpty() )
return;
// find matches in function names
QStringList fnames = FunctionManager::instance()->functionList(FunctionManager::All);
QStringList choices;
TQStringList fnames = FunctionManager::instance()->functionList(FunctionManager::All);
TQStringList choices;
for( unsigned i=0; i<fnames.count(); i++ )
if( fnames[i].startsWith( id, false ) )
if( fnames[i].tqstartsWith( id, false ) )
{
QString str = fnames[i];
TQString str = fnames[i];
::Function* f = FunctionManager::instance()->function( str );
if( f && !f->description.isEmpty() )
@ -512,17 +512,17 @@ void Editor::triggerAutoComplete()
choices.sort();
// find matches in variables names
QStringList vchoices;
QStringList values = ValueManager::instance()->valueNames();
TQStringList vchoices;
TQStringList values = ValueManager::instance()->valueNames();
for(QStringList::ConstIterator it = values.begin(); it != values.end(); ++it)
if( (*it).startsWith( id, false ) )
for(TQStringList::ConstIterator it = values.begin(); it != values.end(); ++it)
if( (*it).tqstartsWith( id, false ) )
{
QString choice = ValueManager::description(*it);
TQString choice = ValueManager::description(*it);
if(choice.isEmpty())
choice = ValueManager::instance()->value(*it).toString();
vchoices.append( QString("%1:%2").arg( *it, choice ) );
vchoices.append( TQString("%1:%2").tqarg( *it, choice ) );
}
vchoices.sort();
@ -534,7 +534,7 @@ void Editor::triggerAutoComplete()
// one match, complete it for the user
if( choices.count()==1 )
{
QString str = QStringList::split( ':', choices[0] )[0];
TQString str = TQStringList::split( ':', choices[0] )[0];
// single perfect match, no need to give choices.
if(str == id.lower())
@ -554,7 +554,7 @@ void Editor::triggerAutoComplete()
d->completion->showCompletion( choices );
}
void Editor::autoComplete( const QString& item )
void Editor::autoComplete( const TQString& item )
{
if( !d->autoCompleteEnabled || item.isEmpty() )
return;
@ -562,7 +562,7 @@ void Editor::autoComplete( const QString& item )
int para = 0, curPos = 0;
getCursorPosition( &para, &curPos );
QString subtext = text().left( curPos );
TQString subtext = text().left( curPos );
Tokens tokens = Evaluator::scan( subtext );
if( !tokens.valid() || tokens.count() < 1 )
@ -572,7 +572,7 @@ void Editor::autoComplete( const QString& item )
if( !lastToken.isIdentifier() )
return;
QStringList str = QStringList::split( ':', item );
TQStringList str = TQStringList::split( ':', item );
blockSignals( true );
setSelection( 0, lastToken.pos(), 0, lastToken.pos()+lastToken.text().length() );
@ -585,7 +585,7 @@ void Editor::autoCalc()
if( !d->autoCalcEnabled )
return;
QString str = Evaluator::autoFix( text() );
TQString str = Evaluator::autoFix( text() );
if( str.isEmpty() )
return;
@ -595,8 +595,8 @@ void Editor::autoCalc()
return;
// If we're using set for a function don't try.
QRegExp setFn("\\s*set.*\\(.*=");
if( str.find(setFn) != -1 )
TQRegExp setFn("\\s*set.*\\(.*=");
if( str.tqfind(setFn) != -1 )
return;
// strip off assignment operator, e.g. "x=1+2" becomes "1+2" only
@ -622,19 +622,19 @@ void Editor::autoCalc()
Abakus::number_t result = parseString(str.latin1());
if( Result::lastResult()->type() == Result::Value )
{
QString ss = QString("Result: <b>%2</b>").arg(result.toString());
TQString ss = TQString("Result: <b>%2</b>").tqarg(result.toString());
d->autoCalcLabel->setText( ss );
d->autoCalcLabel->adjustSize();
// reposition nicely
QPoint pos = mapToGlobal( QPoint( 0, 0 ) );
TQPoint pos = mapToGlobal( TQPoint( 0, 0 ) );
pos.setY( pos.y() - d->autoCalcLabel->height() - 1 );
d->autoCalcLabel->move( pos );
d->autoCalcLabel->show();
d->autoCalcLabel->raise();
// do not show it forever
QTimer::singleShot( 5000, d->autoCalcLabel, SLOT( hide()) );
TQTimer::singleShot( 5000, d->autoCalcLabel, TQT_SLOT( hide()) );
}
else
{
@ -643,7 +643,7 @@ void Editor::autoCalc()
}
}
QString Editor::formatNumber( const Abakus::number_t &value ) const
TQString Editor::formatNumber( const Abakus::number_t &value ) const
{
return value.toString();
}
@ -678,7 +678,7 @@ void Editor::historyForward()
ensureCursorVisible();
}
void Editor::keyPressEvent( QKeyEvent* e )
void Editor::keyPressEvent( TQKeyEvent* e )
{
if( e->key() == Key_Up )
{
@ -708,10 +708,10 @@ void Editor::keyPressEvent( QKeyEvent* e )
checkMatching();
}
QTextEdit::keyPressEvent( e );
TQTextEdit::keyPressEvent( e );
}
void Editor::wheelEvent( QWheelEvent *e )
void Editor::wheelEvent( TQWheelEvent *e )
{
if( e->delta() > 0 )
historyBack();
@ -732,7 +732,7 @@ bool Editor::isSyntaxHighlightEnabled() const
return d->syntaxHighlightEnabled;
}
void Editor::setHighlightColor( ColorType type, QColor color )
void Editor::setHighlightColor( ColorType type, TQColor color )
{
d->highlightColors[ type ] = color;
@ -742,26 +742,26 @@ void Editor::setHighlightColor( ColorType type, QColor color )
d->highlighter->rehighlight();
}
QColor Editor::highlightColor( ColorType type )
TQColor Editor::highlightColor( ColorType type )
{
return d->highlightColors[ type ];
}
EditorCompletion::EditorCompletion( Editor* editor ): QObject( editor )
EditorCompletion::EditorCompletion( Editor* editor ): TQObject( editor )
{
d = new Private;
d->editor = editor;
d->completionPopup = new QVBox( editor->topLevelWidget(), 0, WType_Popup );
d->completionPopup->setFrameStyle( QFrame::Box | QFrame::Plain );
d->completionPopup = new TQVBox( editor->tqtopLevelWidget(), 0, WType_Popup );
d->completionPopup->setFrameStyle( TQFrame::Box | TQFrame::Plain );
d->completionPopup->setLineWidth( 1 );
d->completionPopup->installEventFilter( this );
d->completionPopup->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
d->completionPopup->tqsetSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Minimum);
d->completionListBox = new QListBox( d->completionPopup );
d->completionListBox = new TQListBox( d->completionPopup );
d->completionPopup->setFocusProxy( d->completionListBox );
d->completionListBox->setFrameStyle( QFrame::NoFrame );
d->completionListBox->setFrameStyle( TQFrame::NoFrame );
d->completionListBox->setVariableWidth( true );
d->completionListBox->installEventFilter( this );
}
@ -771,14 +771,14 @@ EditorCompletion::~EditorCompletion()
delete d;
}
bool EditorCompletion::eventFilter( QObject *obj, QEvent *ev )
bool EditorCompletion::eventFilter( TQObject *obj, TQEvent *ev )
{
if ( obj == d->completionPopup || obj == d->completionListBox )
if ( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(d->completionPopup) || TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(d->completionListBox) )
{
if ( ev->type() == QEvent::KeyPress )
if ( ev->type() == TQEvent::KeyPress )
{
QKeyEvent *ke = (QKeyEvent*)ev;
TQKeyEvent *ke = (TQKeyEvent*)ev;
if ( ke->key() == Key_Enter || ke->key() == Key_Return )
{
doneCompletion();
@ -792,11 +792,11 @@ bool EditorCompletion::eventFilter( QObject *obj, QEvent *ev )
d->completionPopup->close();
d->editor->setFocus();
QApplication::sendEvent( d->editor, ev );
TQApplication::sendEvent( d->editor, ev );
return true;
}
if ( ev->type() == QEvent::MouseButtonDblClick )
if ( ev->type() == TQEvent::MouseButtonDblClick )
{
doneCompletion();
return true;
@ -814,7 +814,7 @@ void EditorCompletion::doneCompletion()
emit selectedCompletion( d->completionListBox->currentText() );
}
void EditorCompletion::showCompletion( const QStringList &choices )
void EditorCompletion::showCompletion( const TQStringList &choices )
{
static bool shown = false;
if( !choices.count() ) return;
@ -838,14 +838,14 @@ void EditorCompletion::showCompletion( const QStringList &choices )
// size of the pop-up
d->completionPopup->setMaximumHeight( 120 );
d->completionPopup->resize( d->completionListBox->sizeHint() +
QSize( d->completionListBox->verticalScrollBar()->width() + 4,
d->completionPopup->resize( d->completionListBox->tqsizeHint() +
TQSize( d->completionListBox->verticalScrollBar()->width() + 4,
d->completionListBox->horizontalScrollBar()->height() + 4 ) );
if(!shown)
{
d->completionPopup->show();
QTimer::singleShot ( 0, this, SLOT(moveCompletionPopup()) );
TQTimer::singleShot ( 0, this, TQT_SLOT(moveCompletionPopup()) );
}
else
{
@ -860,14 +860,14 @@ void EditorCompletion::moveCompletionPopup()
int w = d->completionListBox->width();
// position, reference is editor's cursor position in global coord
QFontMetrics fm( d->editor->font() );
TQFontMetrics fm( d->editor->font() );
int para = 0, curPos = 0;
d->editor->getCursorPosition( &para, &curPos );
int pixelsOffset = fm.width( d->editor->text(), curPos );
pixelsOffset -= d->editor->contentsX();
QPoint pos = d->editor->mapToGlobal( QPoint( pixelsOffset, d->editor->height() ) );
TQPoint pos = d->editor->mapToGlobal( TQPoint( pixelsOffset, d->editor->height() ) );
// if popup is partially invisible, move to other position
NETRootInfo info(d->completionPopup->x11Display(),
@ -876,7 +876,7 @@ void EditorCompletion::moveCompletionPopup()
info.activate(); // wtf is this needed for?
NETRect NETarea = info.workArea(info.currentDesktop());
QRect area(NETarea.pos.x, NETarea.pos.y, NETarea.size.width, NETarea.size.height);
TQRect area(NETarea.pos.x, NETarea.pos.y, NETarea.size.width, NETarea.size.height);
if( pos.y() + h > area.y() + area.height() )
pos.setY( pos.y() - h - d->editor->height() );


+ 26
- 24
src/editor.h View File

@ -23,20 +23,21 @@
#ifndef ABAKUS_EDITOR_H
#define ABAKUS_EDITOR_H
#include <qobject.h>
#include <qstringlist.h>
#include <qtextedit.h>
#include <tqobject.h>
#include <tqstringlist.h>
#include <tqtextedit.h>
#include "hmath.h"
class QEvent;
class QKeyEvent;
class QWidget;
class TQEvent;
class TQKeyEvent;
class TQWidget;
class Evaluator;
class Editor : public QTextEdit
class Editor : public TQTextEdit
{
Q_OBJECT
TQ_OBJECT
public:
@ -45,14 +46,14 @@ class Editor : public QTextEdit
Number, FunctionName, Variable, MatchedPar
} ColorType;
Editor( QWidget* parent = 0, const char* name = 0 );
Editor( TQWidget* tqparent = 0, const char* name = 0 );
~Editor();
QSize sizeHint() const;
QSize xminimumSizeHint() const;
TQSize tqsizeHint() const;
TQSize xtqminimumSizeHint() const;
QStringList history() const;
void setHistory( const QStringList& history );
TQStringList history() const;
void setHistory( const TQStringList& history );
bool autoCompleteEnabled() const;
void setAutoCompleteEnabled( bool enable );
@ -64,22 +65,22 @@ class Editor : public QTextEdit
void setSyntaxHighlight( bool enable );
bool isSyntaxHighlightEnabled() const;
void setHighlightColor( ColorType type, QColor color );
QColor highlightColor( ColorType type );
void setHighlightColor( ColorType type, TQColor color );
TQColor highlightColor( ColorType type );
public slots:
void appendHistory( const QString& text );
void appendHistory( const TQString& text );
void clearHistory();
// Stop the timer from going off.
void squelchNextAutoCalc();
void setText(const QString &txt);
void setText(const TQString &txt);
protected slots:
void checkAutoComplete();
void triggerAutoComplete();
void autoComplete( const QString& item );
void autoComplete( const TQString& item );
void checkAutoCalc();
void autoCalc();
void checkMatching();
@ -89,9 +90,9 @@ class Editor : public QTextEdit
void historyForward();
protected:
void keyPressEvent( QKeyEvent* );
void wheelEvent( QWheelEvent* );
QString formatNumber( const Abakus::number_t &value ) const;
void keyPressEvent( TQKeyEvent* );
void wheelEvent( TQWheelEvent* );
TQString formatNumber( const Abakus::number_t &value ) const;
private:
class Private;
@ -101,23 +102,24 @@ class Editor : public QTextEdit
};
class EditorCompletion : public QObject
class EditorCompletion : public TQObject
{
Q_OBJECT
TQ_OBJECT
public:
EditorCompletion( Editor* editor );
~EditorCompletion();
bool eventFilter( QObject *o, QEvent *e );
bool eventFilter( TQObject *o, TQEvent *e );
void doneCompletion();
void showCompletion( const QStringList &choices );
void showCompletion( const TQStringList &choices );
protected slots:
void moveCompletionPopup();
signals:
void selectedCompletion( const QString& item );
void selectedCompletion( const TQString& item );
private:
class Private;


+ 21
- 21
src/evaluator.cpp View File

@ -24,11 +24,11 @@
#include "node.h" // For parser_yacc.hpp below
#include "parser_yacc.hpp"
#include <qapplication.h>
#include <qmap.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qvaluevector.h>
#include <tqapplication.h>
#include <tqmap.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqvaluevector.h>
#include <kdebug.h>
@ -44,15 +44,15 @@ Evaluator::~Evaluator()
{
}
void Evaluator::setExpression(const QString &expr)
void Evaluator::setExpression(const TQString &expr)
{
kdError() << k_funcinfo << " not implemented.\n";
}
QString Evaluator::expression() const
TQString Evaluator::expression() const
{
kdError() << k_funcinfo << " not implemented.\n";
return QString();
return TQString();
}
void Evaluator::clear()
@ -72,7 +72,7 @@ Tokens Evaluator::tokens() const
return Tokens();
}
Tokens Evaluator::scan(const QString &expr)
Tokens Evaluator::scan(const TQString &expr)
{
Lexer l(expr);
Tokens tokens;
@ -118,7 +118,7 @@ Tokens Evaluator::scan(const QString &expr)
return tokens;
}
QString Evaluator::error() const
TQString Evaluator::error() const
{
kdError() << k_funcinfo << " not implemented.\n";
return "No Error Yet";
@ -133,14 +133,14 @@ const Token Token::null;
// helper function: return operator of given token text
// e.g. "*" yields Operator::Asterisk, and so on
static Token::Op matchOperator( const QString& text )
static Token::Op matchOperator( const TQString& text )
{
Token::Op result = Token::InvalidOp;
if( text.length() == 1 )
{
QChar p = text[0];
switch( p.unicode() )
TQChar p = text[0];
switch( p.tqunicode() )
{