diff --git a/docs/manpages/rd.conf.xml b/docs/manpages/rd.conf.xml new file mode 100644 index 00000000..e69de29b diff --git a/lib/rdpushbutton.cpp b/lib/rdpushbutton.cpp index 1941e6a3..3cbf95ec 100644 --- a/lib/rdpushbutton.cpp +++ b/lib/rdpushbutton.cpp @@ -30,27 +30,57 @@ #include <rdpushbutton.h> -RDPushButton::RDPushButton(QWidget *parent=0) - : QPushButton(parent), RDFontEngine(font()) +RDPushButton::RDPushButton(QWidget *parent=0,RDConfig *c) + : QPushButton(parent), RDFontEngine(font(),c) { Init(); } -RDPushButton::RDPushButton(const QString &text,QWidget *parent) - : QPushButton(text,parent), RDFontEngine(font()) +RDPushButton::RDPushButton(const QString &text,QWidget *parent,RDConfig *c) + : QPushButton(text,parent), RDFontEngine(font(),c) { + plain_text=text; Init(); } RDPushButton::RDPushButton(const QIcon &icon,const QString &text, - QWidget *parent) - : QPushButton(text,parent), RDFontEngine(font()) + QWidget *parent,RDConfig *c) + : QPushButton(text,parent), RDFontEngine(font(),c) { + plain_text=text; Init(); } +QString RDPushButton::text() const +{ + return plain_text; +} + + +void RDPushButton::setText(const QString &str) +{ + plain_text=str; + ComposeText(); +} + + +bool RDPushButton::wordWrap() const +{ + return word_wrap_enabled; +} + + +void RDPushButton::setWordWrap(bool state) +{ + if(word_wrap_enabled!=state) { + word_wrap_enabled=state; + ComposeText(); + } +} + + QColor RDPushButton::flashColor() const { return flash_color; @@ -267,6 +297,52 @@ void RDPushButton::flashOff() } +void RDPushButton::ComposeText() +{ + int lines; + QStringList f0=plain_text.split(" ",QString::SkipEmptyParts); + QFont font(buttonFont().family(),(double)size().height()/2.0,QFont::Bold); + QString accum; + QString text; + int height; + bool singleton; + int w=90*size().width()/100; + int h=90*size().height()/100; + + if(word_wrap_enabled) { + do { + singleton=false; + accum=""; + text=""; + font=QFont(font.family(),font.pointSize()-2,QFont::Bold); + QFontMetrics fm(font); + lines=1; + for(int i=0;i<f0.size();i++) { + if((fm.width(accum+f0.at(i)+" "))>w) { + if(fm.width(f0.at(i))>w) { + singleton=true; + break; + } + lines++; + accum=f0.at(i)+" "; + text+="\n"; + } + else { + accum+=f0.at(i)+" "; + } + text+=f0.at(i)+" "; + } + height=lines*fm.lineSpacing(); + } while(singleton||(((height>h))&&(font.pointSize()>6))); + QPushButton::setText(text.trimmed()); + QPushButton::setFont(font); + } + else { + QPushButton::setText(plain_text); + } +} + + void RDPushButton::Init() { flash_timer=new QTimer(); @@ -277,6 +353,7 @@ void RDPushButton::Init() flash_clock_source=RDPushButton::InternalClock; flash_period=RDPUSHBUTTON_DEFAULT_FLASH_PERIOD; setFlashColor(RDPUSHBUTTON_DEFAULT_FLASH_COLOR); + word_wrap_enabled=false; button_id=-1; } diff --git a/lib/rdpushbutton.h b/lib/rdpushbutton.h index 51c9713d..34cf393f 100644 --- a/lib/rdpushbutton.h +++ b/lib/rdpushbutton.h @@ -25,7 +25,6 @@ #include <qpushbutton.h> #include <qpixmap.h> #include <qcolor.h> -//Added by qt3to4: #include <QMouseEvent> #include <rdfontengine.h> @@ -41,9 +40,14 @@ class RDPushButton : public QPushButton, public RDFontEngine Q_OBJECT public: enum ClockSource {InternalClock=0,ExternalClock=1}; - RDPushButton(QWidget *parent); - RDPushButton(const QString &text,QWidget *parent); - RDPushButton(const QIcon &icon,const QString &text,QWidget *parent); + RDPushButton(QWidget *parent,RDConfig *c=NULL); + RDPushButton(const QString &text,QWidget *parent,RDConfig *c=NULL); + RDPushButton(const QIcon &icon,const QString &text,QWidget *parent, + RDConfig *c=NULL); + QString text() const; + void setText(const QString &str); + bool wordWrap() const; + void setWordWrap(bool state); QColor flashColor() const; void setFlashColor(QColor color); int flashPeriod() const; @@ -78,6 +82,9 @@ class RDPushButton : public QPushButton, public RDFontEngine void flashOn(); void flashOff(); void Init(); + void ComposeText(); + QString plain_text; + bool word_wrap_enabled; bool flash_state; int flash_period; bool flashing_enabled; @@ -90,5 +97,4 @@ class RDPushButton : public QPushButton, public RDFontEngine }; - #endif // RDPUSHBUTTON_H diff --git a/utils/rdsoftkeys/rdsoftkeys.cpp b/utils/rdsoftkeys/rdsoftkeys.cpp index 34d82931..128115f1 100644 --- a/utils/rdsoftkeys/rdsoftkeys.cpp +++ b/utils/rdsoftkeys/rdsoftkeys.cpp @@ -24,10 +24,12 @@ #include <qapplication.h> #include <qmessagebox.h> #include <rdprofile.h> -#include <qpushbutton.h> #include <qsignalmapper.h> #include <qtranslator.h> +#include <rdfontengine.h> +#include <rdpushbutton.h> + #include "rdsoftkeys.h" // @@ -36,7 +38,7 @@ #include "../icons/rivendell-22x22.xpm" MainWidget::MainWidget(QWidget *parent) - : RDWidget(parent) + : QWidget(parent) { key_ysize=70; @@ -45,7 +47,6 @@ MainWidget::MainWidget(QWidget *parent) // RDConfig *config=new RDConfig(); QString map_filename=config->filename(); - delete config; RDCmdSwitch *cmd= new RDCmdSwitch(qApp->argc(),qApp->argv(),"rdsoftkeys",RDSOFTKEYS_USAGE); for(unsigned i=0;i<cmd->keys();i++) { @@ -71,7 +72,7 @@ MainWidget::MainWidget(QWidget *parent) // // Create Buttons // - QPushButton *button; + RDPushButton *button; QString rmlcmd; int n=0; QString color_name; @@ -96,13 +97,12 @@ MainWidget::MainWidget(QWidget *parent) if(rmlcmd.at(i)==':') { key_macros.push_back(rmlcmd.right(rmlcmd.length()-(i+1))); key_addrs.push_back(rmlcmd.left(i)); - button=new QPushButton(this); + button=new RDPushButton(this,config); button->setGeometry(10+90*col,10+60*row,80,50); - button-> - setText(WrapText(button,profile-> - stringValue("SoftKeys",QString(). - sprintf("Legend%d",n+1), - QString().sprintf("Button %d",n+1)))); + button->setWordWrap(true); + button->setText( + profile->stringValue("SoftKeys",QString().sprintf("Legend%d",n+1), + QString().sprintf("Button %d",n+1))); if(!(color_name=profile->stringValue("SoftKeys", QString().sprintf("Color%d",n+1),"")). isEmpty()) { @@ -155,10 +155,8 @@ MainWidget::MainWidget(QWidget *parent) // // Set Window Size // - setMinimumWidth(sizeHint().width()); - setMaximumWidth(sizeHint().width()); - setMinimumHeight(sizeHint().height()); - setMaximumHeight(sizeHint().height()); + setMinimumSize(sizeHint()); + setMaximumSize(sizeHint()); } @@ -209,60 +207,6 @@ void MainWidget::closeEvent(QCloseEvent *e) } -QString MainWidget::WrapText(QWidget *w,const QString &text) -{ - QFontMetrics fm(w->font()); - QString str; - QString residue = text; - bool space_found=false; - int l; - int lines=0; - - if(!text.isEmpty()) { - while(!residue.isEmpty()) { - space_found=false; - for(int i=(int)residue.length();i>=0;i--) { - if((i==((int)residue.length()))||(residue.at(i).isSpace())) { - if(fm.boundingRect(residue.left(i)).width()<=w->width()-6) { - space_found=true; - if(!str.isEmpty()) { - str+="\n"; - if(++lines==3) { - return str; - } - } - str+=residue.left(i); - if(i==(int)residue.length()) { - return str; - } - residue=residue.right(residue.length()-i-1); - } - } - } - if(!space_found) { - l=residue.length(); - for(int i=l;i>=0;i--) { - if(fm.boundingRect(residue.left(i)).width()<=(w->width()-6)) { - if(!str.isEmpty()) { - str+="\n"; - if(++lines==3) { - return str; - } - } - str+=residue.left(i); - if(i==(int)residue.length()) { - return str; - } - residue=residue.right(residue.length()-i-1); - } - } - } - } - } - return text; -} - - int main(int argc,char *argv[]) { QApplication::setStyle(RD_GUI_STYLE); diff --git a/utils/rdsoftkeys/rdsoftkeys.h b/utils/rdsoftkeys/rdsoftkeys.h index 52779153..5b24dcdb 100644 --- a/utils/rdsoftkeys/rdsoftkeys.h +++ b/utils/rdsoftkeys/rdsoftkeys.h @@ -22,8 +22,7 @@ #define RDSOFTKEYS_H #include <q3socketdevice.h> - -#include <rdwidget.h> +#include <qwidget.h> // // Settings @@ -31,7 +30,7 @@ #define RDSOFTKEYS_USAGE "[--map-file=<filename>]\n\nWhere <filename> is the name of the file load soft key definitions from.\nThe default value is master Rivendell configuration file.\n" #define RDSOFTKEYS_DEFAULT_COLUMNS 1 -class MainWidget : public RDWidget +class MainWidget : public QWidget { Q_OBJECT public: @@ -44,7 +43,6 @@ class MainWidget : public RDWidget void closeEvent(QCloseEvent *e); private: - QString WrapText(QWidget *w,const QString &text); QPixmap *key_icon_map; Q3SocketDevice *key_socket; unsigned key_columns;