init
This commit is contained in:
59
device/ui/devicesysteminfowidget.cpp
Normal file
59
device/ui/devicesysteminfowidget.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include"devicesysteminfowidget.h"
|
||||
#include "ui_devicesysteminfowidget.h"
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include "deviceinfo.h"
|
||||
|
||||
|
||||
DeviceSystemInfoWidget::DeviceSystemInfoWidget(QWidget *parent):
|
||||
QFrame(parent),
|
||||
ui(new Ui::DeviceSystemInfoWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
// 获取文本光标(不是鼠标光标)
|
||||
cursorPosition = ui->textEdit->textCursor();
|
||||
|
||||
//insertInformationToText("杭州");
|
||||
//insertInformationToText("中国");
|
||||
connect(DEVICE_INFO,SIGNAL(deviceSystemInfoSGL(const QString,SYS_INFO_LEVEL)),this,SLOT(insertInformationToText(const QString&,SYS_INFO_LEVEL)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
DeviceSystemInfoWidget::~DeviceSystemInfoWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DeviceSystemInfoWidget::insertInformationToText(const QString text,SYS_INFO_LEVEL level)
|
||||
{
|
||||
cursorPosition.movePosition(QTextCursor::Start,QTextCursor::MoveAnchor);
|
||||
cursorPosition.insertText("\n");
|
||||
cursorPosition.movePosition(QTextCursor::Start,QTextCursor::MoveAnchor);
|
||||
cursorPosition.insertText(text);
|
||||
//选中该行文字
|
||||
cursorPosition.movePosition(QTextCursor::Start,QTextCursor::MoveAnchor);
|
||||
//qDebug()<<"------text.length(): "<<text.length()<<endl;
|
||||
cursorPosition.setPosition(cursorPosition.position() + text.length(),QTextCursor::KeepAnchor);
|
||||
// 只选单词,不选数字
|
||||
//cursorPosition.select(QTextCursor::WordUnderCursor);
|
||||
//cursorPosition.select(QTextCursor::LineUnderCursor);
|
||||
cursorPosition.select(QTextCursor::BlockUnderCursor);
|
||||
|
||||
QTextCharFormat fmt;
|
||||
switch (level)
|
||||
{
|
||||
case D_NOTHING:
|
||||
fmt.setForeground(QColor(255, 255, 255));
|
||||
break;
|
||||
case D_WARNING:
|
||||
fmt.setForeground(QColor(255, 160, 14));
|
||||
break;
|
||||
case D_CRITICAL:
|
||||
fmt.setForeground(QColor(255, 53, 21));
|
||||
break;
|
||||
}
|
||||
// 把格式应用到光标所处在的字符上
|
||||
cursorPosition.mergeCharFormat(fmt);
|
||||
cursorPosition.clearSelection(); //撤销选中
|
||||
}
|
||||
Reference in New Issue
Block a user