能够新建布局,也是数据可视化大屏界面电子看板系统中的必备功能之一,新建布局这样的功能一般做到右键菜单中,单击新建布局菜单,弹出输入框要求输入新的布局的名称,为了更符合国情,直接支持中文名称,保存成配置文件直接中文名称命名,这样方便用户理解,Qt5以来对乱码的问题解决的就比较好了,不像Qt4时代稍不留神就乱码了,Qt5只要保证源码文件utf-8编码基本上就很少遇到乱码问题了。新建布局必须要有个默认的窗体排列,Qt中的dock窗体,默认布局会以窗体的sizehint作为大小参照标准,也不一定是完全正确的,还跟窗体中的子控件有关系,不过这些都不影响布局以后重新从配置文件加载的布局,QMainWindow提供saveState()函数直接保存当前窗体的所有布局位置大小等信息到配置文件,至于配置文件的内容格式,那是人类无法理解的格式,反正我是看不懂,这些都没有关系的,你重新用restoreState()函数加载读取配置文件的信息时,会自动应用,这样就很爽很完美了。
电子看板是目视化管理的一种表现形式,即对数据的状况一目了然地表现,主要是对于管理项目,它通过利用形象直观而又色彩适宜的各种视觉感知信息来组织现场生产活动,目视管理依据人类的生理特征,在生产现场充分利用信号灯、标识牌、符号颜色等方式来发出视觉信号,鲜明准确地刺激人的神经末梢,快速地传递信息,形象直观地将潜在的问题和浪费现象都显现出来。以便任何人都可以及时掌握管理现状和必要的情报,从而能够快速制定并实施应对措施。因此,管理看板是发现问题、解决问题的非常有效且直观的手段,是优秀的现场管理必不可少的工具之一。
#include "frmmodulecenter.h"
#include "ui_frmmodulecenter.h"
#include "quiwidget.h"
frmModuleCenter::frmModuleCenter(QWidget *parent) : QWidget(parent), ui(new Ui::frmModuleCenter)
{
ui->setupUi(this);
this->initForm();
}
frmModuleCenter::~frmModuleCenter()
{
delete ui;
}
bool frmModuleCenter::eventFilter(QObject *watched, QEvent *event)
{
if (watched == this) {
if (event->type() == QEvent::MouseButtonPress) {
if (qApp->mouseButtons() == Qt::RightButton) {
menuMain->exec(QCursor::pos());
}
}
}
return QWidget::eventFilter(watched, event);
}
void frmModuleCenter::initForm()
{
ui->labName->setText(App::Title);
this->installEventFilter(this);
//鼠标右键菜单
menuMain = new QMenu(this);
//从目录下找布局文件自动生成菜单
menuLayout = menuMain->addMenu("布局方案");
QDir dir(QUIHelper::appPath() + "/layout");
QStringList files = dir.entryList(QStringList() << "*.ini");
foreach (QString file, files) {
QString name = file.split(".").first();
menuLayout->addAction(name, this, SLOT(changeLayout()));
}
menuTheme = menuMain->addMenu("配色方案");
menuTheme->addAction("紫色风格", this, SLOT(changeTheme()));
menuTheme->addAction("蓝色风格", this, SLOT(changeTheme()));
menuTheme->addAction("深蓝风格", this, SLOT(changeTheme()));
menuTheme->addAction("黑色风格", this, SLOT(changeTheme()));
menuTheme->addAction("自定义风格", this, SLOT(changeTheme()));
menuMain->addSeparator();
menuMain->addAction("新建布局", this, SLOT(doAction()));
menuMain->addAction("恢复布局", this, SLOT(doAction()));
menuMain->addAction("保存布局", this, SLOT(doAction()));
menuMain->addAction("布局另存", this, SLOT(doAction()));
menuMain->addSeparator();
menuMain->addAction("截取屏幕", this, SLOT(doAction()));
menuMain->addAction("退出系统", this, SLOT(doAction()));
//设置菜单允许复选框+选中配置文件对应菜单
actionLayout = menuLayout->actions();
foreach (QAction *action, actionLayout) {
action->setCheckable(true);
action->setChecked(action->text() == App::Layout);
}
actionTheme = menuTheme->actions();
foreach (QAction *action, actionTheme) {
action->setCheckable(true);
action->setChecked(action->text() == App::Theme);
}
}
void frmModuleCenter::changeLayout()
{
QAction *ac = (QAction *)sender();
emit changeLayout(ac->text());
foreach (QAction *action, actionLayout) {
action->setChecked(action == ac);
}
}
void frmModuleCenter::changeTheme()
{
QAction *ac = (QAction *)sender();
emit changeTheme(ac->text());
foreach (QAction *action, actionTheme) {
action->setChecked(action == ac);
}
}
void frmModuleCenter::addLayout(const QString &layout, int type)
{
if (!layout.isEmpty()) {
//判断名称不能重复
foreach (QAction *action, actionLayout) {
if (action->text() == layout) {
QUIHelper::showMessageBoxError("布局已经存在,请重新输入!", 3);
return;
}
}
//增加右键菜单中的布局子菜单
QAction *action = menuLayout->addAction(layout, this, SLOT(changeLayout()));
//取消原有所有选中
foreach (QAction *action, actionLayout) {
action->setChecked(false);
}
action->setCheckable(true);
action->setChecked(true);
actionLayout.append(action);
emit saveLayout(layout, type);
}
}
void frmModuleCenter::doAction()
{
QAction *action = (QAction *)sender();
QString text = action->text();
if (text == "新建布局") {
QString layout = QUIHelper::showInputBox("布局名称");
addLayout(layout, 0);
} else if (text == "恢复布局") {
emit saveLayout("", 1);
} else if (text == "保存布局") {
if (QUIHelper::showMessageBoxQuestion("确定要保存吗?保存后不可恢复!") == QMessageBox::Yes) {
emit saveLayout(App::Layout, 2);
QUIHelper::showMessageBoxInfo("恭喜,保存当前布局成功!", 3);
}
} else if (text == "布局另存") {
QString layout = QUIHelper::showInputBox("布局名称");
addLayout(layout, 3);
} else if (text == "截取屏幕") {
QWidget *w = (QWidget *)this->parent();
if (w == 0) {
return;
}
QPixmap pix;
int x = 0;
int y = 0;
int width = w->width() - 0;
int height = w->height() - 0;
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
pix = pix.grabWindow(w->winId(), x, y, width, height);
#else
QScreen *pscreen = QApplication::primaryScreen();
pix = pscreen->grabWindow(w->winId(), x, y, width, height);
#endif
QString file = QString("%1/snap/%2_%3.png").arg(QUIHelper::appPath()).arg(App::Theme).arg(App::Layout);
pix.save(file, "png");
} else if (text == "退出系统") {
emit closeAll();
}
}