⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialogoption.cc

📁 c++的guiQt做的开发
💻 CC
字号:
/** @file DialogOption - Abstract class for widget containing one editable string setting, with nearby "..." button allowing to invoke dialog to change the setting in some possibly  more user-friently way Subclasses should reimplement the dialog function to invoke some dialog and change the string value accordingly @author Martin Petricek*/#include "dialogoption.h"#include "settings.h"#include "util.h"#include <QLineEdit>#include <QPushButton>#include <QResizeEvent>#include <QString>namespace gui {/** Default constructor of DialogOption item @param parent parent Option Editor containing this control @param _key Key in settings for this option @param defValue Default value if option not found in configuration */DialogOption::DialogOption(const QString &_key/*=0*/,QWidget *parent/*=0*/,const QString &defValue/*=QString::null*/) : Option (_key,parent) { ed=new QLineEdit(this); setFocusProxy(ed); pb=new QPushButton("..",this); if (!defValue.isNull()) ed->setText(defValue); connect(pb,SIGNAL(clicked()),this,SLOT(invokeDialog())); connect(ed,SIGNAL(textChanged(const QString&)),this,SLOT(enableChange(const QString&)));}/** Called when text changes @param newText value of new text */void DialogOption::enableChange(__attribute__((unused)) const QString &newText) { changed=true;}/** Slot called when user pressed the "..." (invoke dialog) button. Basically, the dialog function is executed and the text is updated*/void DialogOption::invokeDialog() { QString value=ed->text(); dialog(value); ed->setText(value); changed=true;}/** default destructor */DialogOption::~DialogOption() { delete ed;}/** write edited value to settings (using key specified in contructor) */void DialogOption::writeValue() { globalSettings->write(key,ed->text());}/** read value from settings for editing (using key specified in contructor) */void DialogOption::readValue() { QString value=globalSettings->read(key); if (value.isNull()) return; ed->setText(value); changed=false; //Since we've just read the actual setting}/** return size hint of this option editing control @return size hint from inner editbox  */QSize DialogOption::sizeHint() const { return ed->sizeHint();}/** Called on resizing of option editing control Will simply set the same fixed size to inner editbox @param e resize event */void DialogOption::resizeEvent (QResizeEvent *e) { int w=e->size().width(); int h=e->size().height(); if (w<=0 || h<=0) return;//Some invalid size anyway. No need to move the subwidgets pb->move(w-h,0); pb->setFixedSize(QSize(h,h)); ed->move(0,0); ed->setFixedSize(QSize(MAX(0,w-h),h));}} // namespace gui

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -