📄 info.cc
字号:
/** @file Info - Generic key-value information window @author Martin Petricek*/#include "info.h"#include "settings.h"#include "util.h"#include <QAbstractTableModel>#include <QFrame>#include <QGridLayout>#include <QHeaderView>#include <QLabel>#include <QPushButton>#include <QStandardItemModel>#include <QTableView>#include <iostream>namespace gui {using namespace std;/** About Dialog flags */const Qt::WindowFlags aboutDialogFlags=Qt::Dialog;/** constructor of Info, creates window and fills it with elements, parameters are ignored @param data Data to show. Should be map with string keys and string values @param parent Parent window of this dialog @param title Title of the window, show on the window titlebar @param widgetName Identifier that will be used to load and save position and size of this window in settings. If not specified, position will not be loaded or saved */Info::Info(const SMap &data, const QString &title, QWidget *parent/*=0*/,const QString &widgetName/*=QString::null*/):QDialog(parent,aboutDialogFlags) { QWidget::setAttribute(Qt::WA_DeleteOnClose); wName=widgetName; //Window title setWindowTitle(title); QGridLayout *l=new QGridLayout(this); QStringList k=data.keys(); QStandardItemModel* dataModel=new QStandardItemModel(k.size(),2); dataModel->setHeaderData(0,Qt::Horizontal,tr("Key")); dataModel->setHeaderData(1,Qt::Horizontal,tr("Value")); QTableView *lb=new QTableView(this); int idx=0; for(QStringList::iterator i=k.begin();i!=k.end();i++) { dataModel->setData(dataModel->index(idx,0,QModelIndex()),*i); dataModel->setData(dataModel->index(idx,1,QModelIndex()),data.value(*i)); idx++; }// lb->setVerticalHeader(NULL); lb->verticalHeader()->hide(); lb->horizontalHeader()->setStretchLastSection(true); lb->setModel(dataModel); //Lower frame with Ok button QFrame *okFrame=new QFrame(this); QGridLayout *lFrame=new QGridLayout(okFrame); lFrame->setMargin(5); QPushButton *ok=new QPushButton(QObject::tr("&Ok"), okFrame); lFrame->addWidget(ok,0,1); QObject::connect(ok, SIGNAL(clicked()), this, SLOT(close())); okFrame->setFixedHeight(10+ok->sizeHint().height()); l->addWidget(lb,0,0); l->addWidget(okFrame,1,0); if (!wName.isNull()) { globalSettings->restoreWindow(this,wName); } ok->show(); lb->show();}/** default destructor */Info::~Info() { if (!wName.isNull()) { globalSettings->saveWindow(this,wName); }}} // namespace gui
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -