From 3ab207d95e47f81cf75effee3822cd787979cae7 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 1 Dec 2008 15:28:44 +0000 Subject: Added 'compact' attribute in templates. --- client/macrowindow.cc | 5 +++-- client/macrowindow.h | 3 ++- client/mainwindow.cc | 4 +++- client/resumewidget.cc | 36 ++++++++++++++++++++++++++---------- 4 files changed, 34 insertions(+), 14 deletions(-) (limited to 'client') diff --git a/client/macrowindow.cc b/client/macrowindow.cc index 18ed218..ac44b06 100644 --- a/client/macrowindow.cc +++ b/client/macrowindow.cc @@ -43,13 +43,14 @@ extern QString user; extern QString host; extern quint16 port; -MacroWindow::MacroWindow(NetCom *netcom, QDomNode &xml_doc, QString course, bool collapsed) +MacroWindow::MacroWindow(NetCom *netcom, QDomNode &xml_doc, QString course, + bool collapsed, bool compact) : Collapser() { this->course = course; this->netcom = netcom; - setCollapsedWidget(new ResumeWidget()); + setCollapsedWidget(new ResumeWidget(compact)); this->lua = new LUA(this); diff --git a/client/macrowindow.h b/client/macrowindow.h index f42a5a1..76d068c 100644 --- a/client/macrowindow.h +++ b/client/macrowindow.h @@ -47,7 +47,8 @@ class MacroWindow : public Collapser { Q_OBJECT public: - MacroWindow(NetCom *netcom, QDomNode &xml_doc, QString course, bool collapsed = true); + MacroWindow(NetCom *netcom, QDomNode &xml_doc, QString course, + bool collapsed = true, bool compact = false); ~MacroWindow(); bool isClosed(); diff --git a/client/mainwindow.cc b/client/mainwindow.cc index bcb1b4e..0997c53 100644 --- a/client/mainwindow.cc +++ b/client/mainwindow.cc @@ -81,8 +81,10 @@ void MainWindow::update() if(macros.find(macroname) == macros.end()) { bool isstatic = false; + bool iscompact = false; if(xml_elem.attribute("static", "false") == "true") isstatic = true; - macros[macroname] = new MacroWindow(&netcom, macronode, course, !isstatic); + if(xml_elem.attribute("compact", "false") == "true") iscompact = true; + macros[macroname] = new MacroWindow(&netcom, macronode, course, !isstatic, iscompact); QGroupBox *g = new QGroupBox(); g->setTitle(" " + xml_elem.attribute("caption", macroname)); diff --git a/client/resumewidget.cc b/client/resumewidget.cc index d5b1825..6581797 100644 --- a/client/resumewidget.cc +++ b/client/resumewidget.cc @@ -29,30 +29,31 @@ #include #include -//#define RICH -ResumeWidget::ResumeWidget() +#define MAX_COMPACT_SIZE 100 + +//#define RICH // Experimental syntax highlighter (numbers turn blue) + +ResumeWidget::ResumeWidget(bool compact) { + this->compact = compact; setLayout(new QHBoxLayout()); layout()->setContentsMargins(10,2,2,2); - resume = new QLabel("Endnu ikke udfyldt"); + resume = new QLabel("Endnu ikke udfyldt"); #ifdef RICH resume->setTextFormat(Qt::RichText); #endif resume->setWordWrap(true); - resume->setEnabled(false); layout()->addWidget(resume); } void ResumeWidget::setText(QString text) { - resume->setEnabled(true); - -#ifdef RICH QString f; +#ifdef RICH for(int i = 0; i < text.length(); i++) { if(text[i] >= '0' && text[i] <= '9') f += "" + text[i] + ""; else if(text[i] == '\n') f += "
"; @@ -60,10 +61,25 @@ void ResumeWidget::setText(QString text) else f += text[i]; } - resume->setText(f); resume->setWordWrap(true); #else - resume->setText(text); + f = text; #endif -} + if(compact) { + QString origtext = f; + + if(f.count('\n') > 0) f = f.left(f.indexOf('\n')); // Limit to one line. + + if(f.length() > MAX_COMPACT_SIZE) { + f = f.left(MAX_COMPACT_SIZE); // limit to first MAX_COMPACT_SIZE characters. + } + + if(text != f) { + f += " ..."; + resume->setToolTip(origtext); // Only set tooltip if resume has actually been cut off. + } + } + + resume->setText(f); +} -- cgit v1.2.3