Commit d4ba41ad authored by Michael Pyne's avatar Michael Pyne

Remove one major usage of QTreeWidget in abakus.

Remove stray scons-build file.
some cleanups.

svn path=/trunk/playground/utils/abakus/; revision=751504
parent 6c9317dc
......@@ -115,8 +115,7 @@ set(abakus_SRCS
numerictypes.cpp
${CMAKE_CURRENT_BINARY_DIR}/parser_yacc.cpp
result.cpp
resultlistview.cpp
resultlistviewtext.cpp
resultmodel.cpp
rpnmuncher.cpp
valuemanager.cpp
# dcopIface.skel
......
#! /usr/bin/env python
## This script demonstrates how to build and install
## a simple kde program having KconfigXT settings
## with scons
##
## Thomas Nagy, 2004, 2005
## This file can be reused freely for any project (see COPYING)
############################
## load the config
## Use the environment and the tools set in the top-level
## SConstruct file (set with 'Export') - this is very important
Import( 'env' )
myenv=env.Copy()
#############################
## the programs to build
# The sources for our program - only .ui, .skel and .cpp are accepted
abakus_sources = """
abakus.cpp
abakuslistview.cpp
dragsupport.cpp
editor.cpp
evaluator.cpp
function.cpp
lexer_lex.cpp
mainwindow.cpp
node.cpp
numerictypes.cpp
parser_yacc.cpp
result.cpp
resultlistview.cpp
resultlistviewtext.cpp
rpnmuncher.cpp
valuemanager.cpp
dcopIface.skel
"""
if myenv.get('mpfr', 'no') == 'yes':
myenv.Append(LIBS = ['mpfr', 'gmp'])
else:
abakus_sources = abakus_sources + " hmath.cpp number.c"
myenv.KDEprogram( "abakus", abakus_sources )
myenv.KDEicon( 'abakus' )
# Mark these as being created by flex and bison if it's installed.
if myenv.Dictionary().has_key('PARSER_INCLUDED'):
myenv.CXXFile( "lexer_lex.cpp", "lexer.ll" )
myenv.CXXFile( "parser_yacc.cpp", "parser.yy", YACCFLAGS="-d" )
if myenv['HAVE_ASNEEDED']:
myenv.Append(LINKFLAGS = '-Wl,--as-needed')
myenv.Append(CXXFLAGS = '-Wno-non-virtual-dtor')
############################
## Customization
## Additional include paths for compiling the source files
## Always add '../' (top-level directory) because moc makes code that needs it
myenv.KDEaddpaths_includes('#/src/ #/')
## Necessary libraries to link against
myenv.KDEaddlibs( 'qt-mt kio kdecore kdeprint kdeui' )
#############################
## Data to install
## The ui.rc file and the tips go into datadir/appname/
myenv.KDEinstall( 'KDEDATA', 'abakus', 'abakusui.rc' )
## Warning : there is a difference between the normal destop file used for the menu
## and the servicetype desktop file, so they go in different directories
## you will find more information in 'test3'
myenv.KDEinstall( 'KDEMENU', 'Utilities', 'abakus.desktop')
/*
* abakuslistview.cpp - part of abakus
* Copyright (C) 2004, 2005 Michael Pyne <michael.pyne@kdemail.net>
* Copyright (C) 2004, 2005, 2007 Michael Pyne <michael.pyne@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -23,6 +23,7 @@
#include <QtGui/QMenu>
#include <QtGui/QAction>
#include <QtGui/QTreeWidgetItem>
#include <QtGui/QTreeWidgetItemIterator>
#include <QtCore/QList>
//#include <qdragobject.h>
//#include <qheader.h>
......@@ -43,6 +44,21 @@ ListView::ListView(QWidget *parent) :
SLOT(slotItemClicked(QTreeWidgetItem *)));
}
void ListView::redrawItems()
{
QTreeWidgetItemIterator it(this);
while(*it) {
ValueTreeWidgetItem *item = dynamic_cast<ValueTreeWidgetItem *>(*it);
++it;
if(!item)
continue;
item->valueChanged();
}
}
#if 0
QDragObject *ListView::dragObject()
{
......
......@@ -2,7 +2,7 @@
#define ABAKUS_LISTVIEW_H
/*
* abakuslistview.h - part of abakus
* Copyright (C) 2004, 2005 Michael Pyne <michael.pyne@kdemail.net>
* Copyright (C) 2004, 2005, 2007 Michael Pyne <michael.pyne@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -33,6 +33,14 @@ class ListView : public QTreeWidget
public:
ListView(QWidget *parent);
public slots:
/**
* Causes all items to be redrawn. Should be used for when the precision of a value
* changes for example, or other actions that would cause the display of all items
* to become inaccurate.
*/
void redrawItems();
protected:
// virtual QDragObject *dragObject();
......
......@@ -34,24 +34,18 @@
#include <kvbox.h>
#include <khbox.h>
#include <qlayout.h>
#include <qradiobutton.h>
#include <qbuttongroup.h>
#include <qsplitter.h>
#include <QtGui/QLineEdit>
#include <QtGui/QContextMenuEvent>
#include <QtGui>
#include "editor.h"
#include "evaluator.h"
#include "function.h"
#include "resultlistview.h"
#include "resultlistviewtext.h"
#include "valuemanager.h"
#include "node.h"
#include "rpnmuncher.h"
//#include "dcopIface.h"
#include "abakuslistview.h"
#include "result.h"
#include "resultmodel.h"
MainWindow::MainWindow() : KXmlGuiWindow(0), m_popup(0), m_insert(false)
{
......@@ -62,7 +56,7 @@ MainWindow::MainWindow() : KXmlGuiWindow(0), m_popup(0), m_insert(false)
QVBoxLayout *layout = new QVBoxLayout(box);
m_layout = layout;
layout->setSpacing(6);
layout->setMargin(6);
layout->setMargin(0);
QWidget *configBox = new QWidget(box);
layout->addWidget(configBox);
......@@ -99,15 +93,20 @@ MainWindow::MainWindow() : KXmlGuiWindow(0), m_popup(0), m_insert(false)
m_history->setSpacing(6);
m_history->setMargin(0);
m_result = new ResultListView(m_history);
m_result->setSelectionMode(ResultListView::NoSelection);
m_result->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
connect(m_result, SIGNAL(signalEntrySelected(const QString &)),
SLOT(slotEntrySelected(const QString &)));
connect(m_result, SIGNAL(signalResultSelected(const QString &)),
SLOT(slotResultSelected(const QString &)));
m_history->setStretchFactor(m_result, 1);
m_resultItemModel = new ResultModel(this);
QTreeView *resultList = new QTreeView(m_history);
resultList->setSelectionMode(QTreeView::NoSelection);
resultList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
resultList->setModel(m_resultItemModel->model());
resultList->header()->setResizeMode(QHeaderView::ResizeToContents);
resultList->setAlternatingRowColors(true);
resultList->setRootIsDecorated(false);
connect(m_resultItemModel, SIGNAL(signalColumnChanged(int)),
resultList, SLOT(resizeColumnToContents(int)));
connect(resultList, SIGNAL(clicked(const QModelIndex &)),
this, SLOT(itemClicked(const QModelIndex &)));
m_history->setStretchFactor(resultList, 1);
layout->setStretchFactor(m_history, 1);
KHBox *editBox = new KHBox(box);
......@@ -123,7 +122,8 @@ MainWindow::MainWindow() : KXmlGuiWindow(0), m_popup(0), m_insert(false)
connect(evalButton, SIGNAL(clicked()), SLOT(slotEvaluate()));
connect(m_edit, SIGNAL(returnPressed()), SLOT(slotReturnPressed()));
connect(m_edit, SIGNAL(textChanged()), SLOT(slotTextChanged()));
connect(m_edit, SIGNAL(textChanged(const QString &)),
this, SLOT(slotTextChanged(const QString &)));
m_listSplitter = new QSplitter(Qt::Vertical, m_mainSplitter);
m_fnList = new FunctionListView(m_listSplitter);
......@@ -183,22 +183,20 @@ void MainWindow::slotReturnPressed()
QString text = m_edit->text();
text.replace("\n", "");
if(text.isEmpty())
return;
// TODO: Put this back in, used to be Editor.
// m_edit->appendHistory(text);
// Item to insert after
ResultListViewText *after = m_result->lastItem();
// Expand $foo references.
QString str = interpolateExpression(text, after);
QString str = interpolateExpression(text);
QString resultVal;
ResultListViewText *item;
if(str.isNull())
if(str.isEmpty())
return; // Error already has been posted
QString resultVal;
m_insert = false; // Assume we failed
if(inRPNMode()) {
......@@ -223,7 +221,7 @@ void MainWindow::slotReturnPressed()
return;
}
item = new ResultListViewText(m_result, str, resultVal, after, false);
m_resultItemModel->addResult(str, result);
}
else {
......@@ -246,22 +244,19 @@ void MainWindow::slotReturnPressed()
resultVal = result.toString();
ValueManager::instance()->setValue("ans", result);
if(!compact)
item = new ResultListViewText(m_result, str, result, after, false);
m_resultItemModel->addResult(str, result);
m_insert = true;
break;
case Result::Null: // OK, no result to speak of
resultVal = "OK";
if(!compact)
item = new ResultListViewText(m_result, str, resultVal, after, true);
m_resultItemModel->addMessage(resultVal);
break;
default:
resultVal = Result::lastResult()->message();
if(!compact)
item = new ResultListViewText(m_result, str, resultVal, after, true);
m_resultItemModel->addMessage(resultVal);
}
// Skip creating list view items if in compact mode.
......@@ -275,16 +270,11 @@ void MainWindow::slotReturnPressed()
m_edit->setText(text);
m_result->setCurrentItem(item);
m_result->scrollToItem(item);
QTimer::singleShot(0, m_edit, SLOT(selectAll()));
}
void MainWindow::slotTextChanged()
void MainWindow::slotTextChanged(const QString &str)
{
QString str = m_edit->text();
if(str.length() == 1 && m_insert) {
m_insert = false;
......@@ -567,7 +557,7 @@ void MainWindow::setupLayout()
ta->setText(i18n("C&ustom Precision..."));
ta->setActionGroup(precisionGroup);
QAction *a = ac->addAction("clearHistory", m_result, SLOT(clear()));
QAction *a = ac->addAction("clearHistory", m_resultItemModel, SLOT(clear()));
a->setText(i18n("Clear &History"));
a->setIcon(KIcon("editclear"));
ta->setShortcut(Qt::SHIFT + Qt::ALT + Qt::Key_L);
......@@ -728,7 +718,7 @@ void MainWindow::slotToggleExpressionMode()
{
}
QString MainWindow::interpolateExpression(const QString &text, ResultListViewText *after)
QString MainWindow::interpolateExpression(const QString &text)
{
QString str(text);
QRegExp stackRE("\\$\\d+");
......@@ -739,9 +729,9 @@ QString MainWindow::interpolateExpression(const QString &text, ResultListViewTex
Abakus::number_t value;
unsigned numPos = stackStr.mid(1).toUInt();
if(!m_result->getStackValue(numPos, value)) {
new ResultListViewText(m_result, text, i18n("Marker %1 isn't set").arg(stackStr), after, true);
return QString::null;
if(!m_resultItemModel->stackValue(numPos, value)) {
m_resultItemModel->addMessage(i18n("Marker %1 isn't set", stackStr));
return QString();
}
str.replace(pos, stackStr.length(), value.toString());
......@@ -796,19 +786,8 @@ void MainWindow::slotPrecisionCustom()
void MainWindow::redrawResults()
{
QTreeWidgetItemIterator it(m_result);
while(*it) {
static_cast<ResultListViewText *>(*it)->precisionChanged();
++it;
}
it = QTreeWidgetItemIterator(m_varList);
while(*it) {
static_cast<ValueTreeWidgetItem *>(*it)->valueChanged();
++it;
}
m_resultItemModel->slotRedrawItems();
m_varList->redrawItems();
// Because of the way we implemented the menu, it is possible to deselect
// every possibility, so make sure we have at least one selected.
......@@ -846,6 +825,18 @@ void MainWindow::selectCorrectPrecisionAction()
}
}
void MainWindow::itemClicked(const QModelIndex &index)
{
QStandardItem *item = m_resultItemModel->model()->itemFromIndex(index);
if(!item)
return;
if(item->column() == 0)
slotEntrySelected(item->text());
else if(item->column() == 1)
slotResultSelected(item->text());
}
#include "mainwindow.moc"
// vim: set et ts=8 sw=4:
......@@ -32,15 +32,15 @@ class QListViewItem;
class QSplitter;
class QTimer;
class QMenu;
class QTreeWidget;
class QModelIndex;
class QAction;
//class KComboBox;
//class Editor;
class KVBox;
class ResultListView;
class ResultListViewText;
class ResultModel;
class ListView;
class AbakusIface;
......@@ -59,7 +59,7 @@ class MainWindow : public KXmlGuiWindow
private slots:
void slotReturnPressed();
void slotTextChanged();
void slotTextChanged(const QString &);
void slotEvaluate();
void slotPrecisionAuto();
......@@ -74,6 +74,7 @@ class MainWindow : public KXmlGuiWindow
void slotDegrees();
void slotRadians();
void itemClicked(const QModelIndex &);
void slotEntrySelected(const QString &text);
void slotResultSelected(const QString &text);
......@@ -101,7 +102,7 @@ class MainWindow : public KXmlGuiWindow
void saveConfig();
void setupLayout();
void populateListViews();
QString interpolateExpression(const QString &text, ResultListViewText *after);
QString interpolateExpression(const QString &text);
// Donated via JuK
QAction *action(const char *key) const;
......@@ -117,10 +118,10 @@ class MainWindow : public KXmlGuiWindow
QRadioButton *m_radians;
QLineEdit *m_edit;
QMenu *m_popup;
ResultListView *m_result;
ResultModel *m_resultItemModel;
QString m_lastError;
QBoxLayout *m_layout;
QTreeWidget *m_fnList, *m_varList;
ListView *m_fnList, *m_varList;
QSplitter *m_mainSplitter, *m_listSplitter;
QSize m_newSize, m_oldSize;
......
/*
* resultlistview.cpp - part of abakus
* Copyright (C) 2004, 2005 Michael Pyne <michael.pyne@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <kdebug.h>
#include <klocale.h>
#include <QtGui/QHeaderView>
#include <QtGui/QMenu>
#include <QtGui/QTreeWidgetItem>
#include <QtGui/QClipboard>
#include <QtGui/QApplication>
#include <QtGui/QCursor>
#include <QtGui/QContextMenuEvent>
#include "resultlistview.h"
#include "resultlistviewtext.h"
#include "dragsupport.h"
using DragSupport::makePixmap;
using namespace ResultList;
ResultListView::ResultListView(QWidget *parent) :
QTreeWidget(parent), m_itemRightClicked(0)
{
connect(this, SIGNAL(doubleClicked(QTreeWidgetItem *, const QPoint &, int)),
SLOT(slotDoubleClicked(QTreeWidgetItem *, const QPoint &, int)));
QStringList labels;
labels << i18n("Expression") << i18n("Result") << i18n("Shortcut");
setHeaderLabels(labels);
header()->hide(); // I hate that header
header()->setStretchLastSection(false);
header()->setResizeMode(ResultColumn, QHeaderView::Stretch);
// setDragEnabled(true);
// setItemMargin(2);
// setColumnAlignment(ResultColumn, AlignLeft);
// setColumnAlignment(ShortcutColumn, AlignHCenter);
// setColumnWidthMode(ResultColumn, Maximum);
setSortingEnabled(false);
}
bool ResultListView::getStackValue(unsigned stackPosition, Abakus::number_t &result)
{
QTreeWidgetItem *it = topLevelItem(0);
for(; it; it = itemBelow(it)) {
ResultListViewText *resultItem = dynamic_cast<ResultListViewText *>(it);
if(!resultItem->wasError() && resultItem->stackPosition() == stackPosition) {
QByteArray resultText = resultItem->resultText().toLatin1();
result = Abakus::number_t(resultText.data());
return true;
}
}
return false;
}
#if 0
QDragObject *ResultListView::dragObject()
{
QPoint viewportPos = viewport()->mapFromGlobal(QCursor::pos());
ResultListViewText *item = itemUnderCursor();
if(item) {
QString text = item->resultText();
int column = header()->sectionAt(viewportPos.x());
if(column == ExpressionColumn)
text = item->expressionText();
QDragObject *drag = new QTextDrag(text, this);
drag->setPixmap(makePixmap(text, font()));
return drag;
}
return 0;
}
#endif
void ResultListView::contextMenuEvent(QContextMenuEvent *e)
{
m_itemRightClicked = itemUnderCursor();
QMenu *menu = constructPopupMenu(m_itemRightClicked);
menu->popup(e->globalPos());
}
void ResultListView::slotDoubleClicked(QTreeWidgetItem *item, const QPoint &, int c)
{
ResultListViewText *textItem = dynamic_cast<ResultListViewText *>(item);
if(!textItem)
return;
if(c == ExpressionColumn)
emit signalEntrySelected(textItem->expressionText());
else if(c == ResultColumn)
emit signalResultSelected(textItem->resultText());
}
QMenu *ResultListView::constructPopupMenu(const ResultListViewText *item)
{
QMenu *menu = new QMenu(this);
menu->addAction(i18n("Clear &History"), this, SLOT(clear()), Qt::Key_Alt + Qt::Key_R);
QAction *a = menu->addAction(i18n("Copy Result to Clipboard"), this, SLOT(slotCopyResult()));
if(!item || item->wasError())
a->setEnabled(false);
return menu;
}
void ResultListView::slotCopyResult()
{
if(!m_itemRightClicked)
return;
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(m_itemRightClicked->resultText(), QClipboard::Clipboard);
}
ResultListViewText *ResultListView::lastItem() const
{
return static_cast<ResultListViewText *>(topLevelItem(topLevelItemCount() - 1));
}
ResultListViewText *ResultListView::itemUnderCursor() const
{
QPoint viewportPos = viewport()->mapFromGlobal(QCursor::pos());
QTreeWidgetItem *underCursor = itemAt(viewportPos);
return static_cast<ResultListViewText *>(underCursor);
}
#include "resultlistview.moc"
// vim: set et sw=4 ts=8:
/*
* resultlistviewtext.cpp - part of abakus
* Copyright (C) 2004, 2005 Michael Pyne <michael.pyne@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <kdebug.h>
#include <QtCore/QRegExp>
#include <QtGui/QPainter>
#include <QtGui/QFontMetrics>
#include <QtGui/QFont>
#include <QtGui/QPalette>
#include "resultlistviewtext.h"
using namespace ResultList;
ResultListViewText::ResultListViewText(QTreeWidget *listView,
const QString &text,
const QString &result,
ResultListViewText *after,
bool isError)
: QTreeWidgetItem(listView, after), m_text(text),
m_result(result), m_wasError(isError), m_stackPosition(0)
{
// This is some kind of non-result answer, don't bother worrying about the
// stack status, it hasn't changed.
setText(ExpressionColumn, text);
setText(ResultColumn, result);