allow toggle show text/fields in preview
This commit is contained in:
parent
bc207a3986
commit
631fadc7cf
@ -35,9 +35,11 @@ using std::pair;
|
|||||||
#include <qtabwidget.h>
|
#include <qtabwidget.h>
|
||||||
#if (QT_VERSION < 0x040000)
|
#if (QT_VERSION < 0x040000)
|
||||||
#include <qtextedit.h>
|
#include <qtextedit.h>
|
||||||
|
#include <qpopupmenu.h>
|
||||||
#include <qprogressdialog.h>
|
#include <qprogressdialog.h>
|
||||||
#define THRFINISHED finished
|
#define THRFINISHED finished
|
||||||
#else
|
#else
|
||||||
|
#include <q3popupmenu.h>
|
||||||
#include <q3textedit.h>
|
#include <q3textedit.h>
|
||||||
#include <q3progressdialog.h>
|
#include <q3progressdialog.h>
|
||||||
#include <q3stylesheet.h>
|
#include <q3stylesheet.h>
|
||||||
@ -93,7 +95,7 @@ using std::pair;
|
|||||||
//
|
//
|
||||||
// Problem is, it uses the sem-private qrichtext_p.h, which is not
|
// Problem is, it uses the sem-private qrichtext_p.h, which is not
|
||||||
// even installed under qt4. We use a local copy, which is not nice.
|
// even installed under qt4. We use a local copy, which is not nice.
|
||||||
void QTextEditFixed::moveToAnchor(const QString& name)
|
void PreviewTextEdit::moveToAnchor(const QString& name)
|
||||||
{
|
{
|
||||||
if (name.isEmpty())
|
if (name.isEmpty())
|
||||||
return;
|
return;
|
||||||
@ -135,7 +137,7 @@ void Preview::init()
|
|||||||
QWidget *unnamed = new QWidget(pvTab, "unnamed");
|
QWidget *unnamed = new QWidget(pvTab, "unnamed");
|
||||||
QVBoxLayout *unnamedLayout =
|
QVBoxLayout *unnamedLayout =
|
||||||
new QVBoxLayout(unnamed, 0, 6, "unnamedLayout");
|
new QVBoxLayout(unnamed, 0, 6, "unnamedLayout");
|
||||||
QTextEditFixed *pvEdit = new QTextEditFixed(unnamed, "pvEdit");
|
PreviewTextEdit *pvEdit = new PreviewTextEdit(unnamed, "pvEdit", this);
|
||||||
pvEdit->setReadOnly(TRUE);
|
pvEdit->setReadOnly(TRUE);
|
||||||
pvEdit->setUndoRedoEnabled(FALSE);
|
pvEdit->setUndoRedoEnabled(FALSE);
|
||||||
unnamedLayout->addWidget(pvEdit);
|
unnamedLayout->addWidget(pvEdit);
|
||||||
@ -267,9 +269,9 @@ bool Preview::eventFilter(QObject *target, QEvent *event)
|
|||||||
return QApplication::sendEvent(searchTextLine, event);
|
return QApplication::sendEvent(searchTextLine, event);
|
||||||
} else {
|
} else {
|
||||||
QWidget *tw = pvTab->currentPage();
|
QWidget *tw = pvTab->currentPage();
|
||||||
QTextEditFixed *e = 0;
|
PreviewTextEdit *e = 0;
|
||||||
if (tw)
|
if (tw)
|
||||||
e = (QTextEditFixed *)tw->child("pvEdit");
|
e = (PreviewTextEdit *)tw->child("pvEdit");
|
||||||
LOGDEB1(("Widget: %p, edit %p, target %p\n", tw, e, target));
|
LOGDEB1(("Widget: %p, edit %p, target %p\n", tw, e, target));
|
||||||
if (e && target == e) {
|
if (e && target == e) {
|
||||||
if (keyEvent->key() == Qt::Key_Slash) {
|
if (keyEvent->key() == Qt::Key_Slash) {
|
||||||
@ -311,12 +313,12 @@ void Preview::searchTextLine_textChanged(const QString & text)
|
|||||||
#define QStyleSheetItem Q3StyleSheetItem
|
#define QStyleSheetItem Q3StyleSheetItem
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QTextEditFixed *Preview::getCurrentEditor()
|
PreviewTextEdit *Preview::getCurrentEditor()
|
||||||
{
|
{
|
||||||
QWidget *tw = pvTab->currentPage();
|
QWidget *tw = pvTab->currentPage();
|
||||||
QTextEditFixed *edit = 0;
|
PreviewTextEdit *edit = 0;
|
||||||
if (tw) {
|
if (tw) {
|
||||||
edit = (QTextEditFixed*)tw->child("pvEdit");
|
edit = (PreviewTextEdit*)tw->child("pvEdit");
|
||||||
}
|
}
|
||||||
return edit;
|
return edit;
|
||||||
}
|
}
|
||||||
@ -334,7 +336,7 @@ void Preview::doSearch(const QString &_text, bool next, bool reverse,
|
|||||||
QString text = _text;
|
QString text = _text;
|
||||||
|
|
||||||
bool matchCase = matchCheck->isChecked();
|
bool matchCase = matchCheck->isChecked();
|
||||||
QTextEditFixed *edit = getCurrentEditor();
|
PreviewTextEdit *edit = getCurrentEditor();
|
||||||
if (edit == 0) {
|
if (edit == 0) {
|
||||||
// ??
|
// ??
|
||||||
return;
|
return;
|
||||||
@ -453,7 +455,7 @@ void Preview::selecChanged()
|
|||||||
LOGDEB1(("Selection changed\n"));
|
LOGDEB1(("Selection changed\n"));
|
||||||
if (!m_currentW)
|
if (!m_currentW)
|
||||||
return;
|
return;
|
||||||
QTextEditFixed *edit = (QTextEditFixed*)m_currentW->child("pvEdit");
|
PreviewTextEdit *edit = (PreviewTextEdit*)m_currentW->child("pvEdit");
|
||||||
if (edit == 0) {
|
if (edit == 0) {
|
||||||
LOGERR(("Editor child not found\n"));
|
LOGERR(("Editor child not found\n"));
|
||||||
return;
|
return;
|
||||||
@ -479,7 +481,7 @@ void Preview::textDoubleClicked(int, int)
|
|||||||
LOGDEB2(("Preview::textDoubleClicked\n"));
|
LOGDEB2(("Preview::textDoubleClicked\n"));
|
||||||
if (!m_currentW)
|
if (!m_currentW)
|
||||||
return;
|
return;
|
||||||
QTextEditFixed *edit = (QTextEditFixed *)m_currentW->child("pvEdit");
|
PreviewTextEdit *edit = (PreviewTextEdit *)m_currentW->child("pvEdit");
|
||||||
if (edit == 0) {
|
if (edit == 0) {
|
||||||
LOGERR(("Editor child not found\n"));
|
LOGERR(("Editor child not found\n"));
|
||||||
return;
|
return;
|
||||||
@ -513,11 +515,11 @@ void Preview::closeCurrentTab()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextEditFixed *Preview::addEditorTab()
|
PreviewTextEdit *Preview::addEditorTab()
|
||||||
{
|
{
|
||||||
QWidget *anon = new QWidget((QWidget *)pvTab);
|
QWidget *anon = new QWidget((QWidget *)pvTab);
|
||||||
QVBoxLayout *anonLayout = new QVBoxLayout(anon, 1, 1, "anonLayout");
|
QVBoxLayout *anonLayout = new QVBoxLayout(anon, 1, 1, "anonLayout");
|
||||||
QTextEditFixed *editor = new QTextEditFixed(anon, "pvEdit");
|
PreviewTextEdit *editor = new PreviewTextEdit(anon, "pvEdit", this);
|
||||||
editor->setReadOnly(TRUE);
|
editor->setReadOnly(TRUE);
|
||||||
editor->setUndoRedoEnabled(FALSE );
|
editor->setUndoRedoEnabled(FALSE );
|
||||||
anonLayout->addWidget(editor);
|
anonLayout->addWidget(editor);
|
||||||
@ -559,14 +561,11 @@ void Preview::setCurTabProps(const string &fn, const Rcl::Doc &doc,
|
|||||||
tiptxt += meta_it->second + "\n";
|
tiptxt += meta_it->second + "\n";
|
||||||
pvTab->setTabToolTip(w,QString::fromUtf8(tiptxt.c_str(), tiptxt.length()));
|
pvTab->setTabToolTip(w,QString::fromUtf8(tiptxt.c_str(), tiptxt.length()));
|
||||||
|
|
||||||
for (list<TabData>::iterator it = m_tabData.begin();
|
TabData *d = tabDataForCurrent();
|
||||||
it != m_tabData.end(); it++) {
|
if (d) {
|
||||||
if (it->w == w) {
|
d->fn = fn;
|
||||||
it->fn = fn;
|
d->ipath = doc.ipath;
|
||||||
it->ipath = doc.ipath;
|
d->docnum = docnum;
|
||||||
it->docnum = docnum;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -897,7 +896,7 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load into editor
|
// Load into editor
|
||||||
QTextEditFixed *editor = getCurrentEditor();
|
PreviewTextEdit *editor = getCurrentEditor();
|
||||||
editor->setText("");
|
editor->setText("");
|
||||||
if (highlightTerms) {
|
if (highlightTerms) {
|
||||||
QStyleSheetItem *item =
|
QStyleSheetItem *item =
|
||||||
@ -931,7 +930,11 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
progress.close();
|
progress.close();
|
||||||
|
TabData *d = tabDataForCurrent();
|
||||||
|
if (d) {
|
||||||
|
fdoc.text.clear();
|
||||||
|
d->fdoc = fdoc;
|
||||||
|
}
|
||||||
m_haveAnchors = m_plaintorich.lastanchor != 0;
|
m_haveAnchors = m_plaintorich.lastanchor != 0;
|
||||||
if (searchTextLine->text().length() != 0) {
|
if (searchTextLine->text().length() != 0) {
|
||||||
// If there is a current search string, perform the search
|
// If there is a current search string, perform the search
|
||||||
@ -956,3 +959,41 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
|||||||
LOGDEB(("LoadFileInCurrentTab: returning true\n"));
|
LOGDEB(("LoadFileInCurrentTab: returning true\n"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RCLPOPUP *PreviewTextEdit::createPopupMenu(const QPoint&)
|
||||||
|
{
|
||||||
|
RCLPOPUP *popup = new RCLPOPUP(this);
|
||||||
|
if (m_savedText.isEmpty()) {
|
||||||
|
popup->insertItem(tr("Show fields"), this, SLOT(menuToggleFields()));
|
||||||
|
} else {
|
||||||
|
popup->insertItem(tr("Show main text"), this, SLOT(menuToggleFields()));
|
||||||
|
}
|
||||||
|
return popup;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewTextEdit::menuToggleFields()
|
||||||
|
{
|
||||||
|
if (!m_savedText.isEmpty()) {
|
||||||
|
setText(m_savedText);
|
||||||
|
m_savedText = "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TabData *d = m_preview->tabDataForCurrent();
|
||||||
|
if (!d)
|
||||||
|
return;
|
||||||
|
QString txt = "<html><head></head><body>\n";
|
||||||
|
txt += "<b>" + QString::fromLocal8Bit(d->fn.c_str());
|
||||||
|
if (!d->ipath.empty())
|
||||||
|
txt += "|" + QString::fromUtf8(d->ipath.c_str());
|
||||||
|
txt += "</b><br><br>";
|
||||||
|
txt += "<dl>\n";
|
||||||
|
for (map<string,string>::const_iterator it = d->fdoc.meta.begin();
|
||||||
|
it != d->fdoc.meta.end(); it++) {
|
||||||
|
txt += "<dt>" + QString::fromUtf8(it->first.c_str()) + "</dt> "
|
||||||
|
+ "<dd>" + QString::fromUtf8(it->second.c_str()) + "</dd>\n";
|
||||||
|
}
|
||||||
|
txt += "</dl></body></html>";
|
||||||
|
m_savedText = text();
|
||||||
|
setText(txt);
|
||||||
|
}
|
||||||
|
|||||||
@ -30,25 +30,36 @@ class QLabel;
|
|||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QCheckBox;
|
class QCheckBox;
|
||||||
class QTextEditFixed;
|
class PreviewTextEdit;
|
||||||
|
class Preview;
|
||||||
|
|
||||||
#if (QT_VERSION < 0x040000)
|
#if (QT_VERSION < 0x040000)
|
||||||
#include <qtextedit.h>
|
#include <qtextedit.h>
|
||||||
#include <private/qrichtext_p.h>
|
#include <private/qrichtext_p.h>
|
||||||
#define QTEXTEDIT QTextEdit
|
#define QTEXTEDIT QTextEdit
|
||||||
|
class QPopupMenu;
|
||||||
|
#define RCLPOPUP QPopupMenu
|
||||||
#else
|
#else
|
||||||
#include <q3textedit.h>
|
#include <q3textedit.h>
|
||||||
#include <q3richtext_p.h>
|
#include <q3richtext_p.h>
|
||||||
|
class Q3PopupMenu;
|
||||||
|
#define RCLPOPUP Q3PopupMenu
|
||||||
#define QTEXTEDIT Q3TextEdit
|
#define QTEXTEDIT Q3TextEdit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class QTextEditFixed : public QTEXTEDIT {
|
class PreviewTextEdit : public QTEXTEDIT {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QTextEditFixed( QWidget* parent=0, const char* name=0 )
|
PreviewTextEdit(QWidget* parent, const char* name, Preview *pv)
|
||||||
: QTEXTEDIT(parent, name)
|
: QTEXTEDIT(parent, name), m_preview(pv)
|
||||||
{}
|
{}
|
||||||
void moveToAnchor(const QString& name);
|
void moveToAnchor(const QString& name);
|
||||||
|
public slots:
|
||||||
|
virtual void menuToggleFields();
|
||||||
|
private:
|
||||||
|
virtual RCLPOPUP *createPopupMenu(const QPoint& pos);
|
||||||
|
Preview *m_preview;
|
||||||
|
QString m_savedText;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -59,7 +70,9 @@ class TabData {
|
|||||||
string ipath; // Internal doc path inside file
|
string ipath; // Internal doc path inside file
|
||||||
QWidget *w; // widget for setCurrent
|
QWidget *w; // widget for setCurrent
|
||||||
int docnum; // Index of doc in db search results.
|
int docnum; // Index of doc in db search results.
|
||||||
|
// doc out of internfile (previous fields come from the index) with
|
||||||
|
// main text erased (for space).
|
||||||
|
Rcl::Doc fdoc;
|
||||||
TabData(QWidget *wi)
|
TabData(QWidget *wi)
|
||||||
: w(wi), docnum(-1)
|
: w(wi), docnum(-1)
|
||||||
{}
|
{}
|
||||||
@ -116,7 +129,7 @@ public:
|
|||||||
virtual bool makeDocCurrent(const string &fn, size_t sz,
|
virtual bool makeDocCurrent(const string &fn, size_t sz,
|
||||||
const Rcl::Doc& idoc, int docnum,
|
const Rcl::Doc& idoc, int docnum,
|
||||||
bool sametab = false);
|
bool sametab = false);
|
||||||
|
friend class PreviewTextEdit;
|
||||||
public slots:
|
public slots:
|
||||||
virtual void searchTextLine_textChanged(const QString& text);
|
virtual void searchTextLine_textChanged(const QString& text);
|
||||||
virtual void doSearch(const QString& str, bool next, bool reverse,
|
virtual void doSearch(const QString& str, bool next, bool reverse,
|
||||||
@ -164,11 +177,12 @@ private:
|
|||||||
void init();
|
void init();
|
||||||
virtual void setCurTabProps(const string& fn, const Rcl::Doc& doc,
|
virtual void setCurTabProps(const string& fn, const Rcl::Doc& doc,
|
||||||
int docnum);
|
int docnum);
|
||||||
virtual QTextEditFixed *getCurrentEditor();
|
virtual PreviewTextEdit *getCurrentEditor();
|
||||||
virtual QTextEditFixed *addEditorTab();
|
virtual PreviewTextEdit *addEditorTab();
|
||||||
virtual bool loadFileInCurrentTab(string fn, size_t sz,
|
virtual bool loadFileInCurrentTab(string fn, size_t sz,
|
||||||
const Rcl::Doc& idoc, int dnm);
|
const Rcl::Doc& idoc, int dnm);
|
||||||
TabData *tabDataForCurrent(); // Return auxiliary data pointer for cur tab
|
// Return auxiliary data pointer for cur tab
|
||||||
|
TabData *tabDataForCurrent();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _PREVIEW_W_H_INCLUDED_ */
|
#endif /* _PREVIEW_W_H_INCLUDED_ */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user