Rabbit Remote Control 0.1.0-bate8
Loading...
Searching...
No Matches
FrmWakeOnLan.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include <QLoggingCategory>
4#include <QMessageBox>
5
6#include "FrmWakeOnLan.h"
7#include "ui_FrmWakeOnLan.h"
8
9static Q_LOGGING_CATEGORY(log, "WakeOnLan.CFrmWakeOnLan")
10CFrmWakeOnLan::CFrmWakeOnLan(CWakeOnLanModel *pModel, QWidget *parent)
11 : QWidget(parent)
12 , ui(new Ui::CFrmWakeOnLan)
13{
14 bool check = false;
15 ui->setupUi(this);
16 ui->tableView->setModel(pModel);
17 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
18 ui->tableView->installEventFilter(this);
19 check = connect(ui->tableView,
20 SIGNAL(customContextMenuRequested(const QPoint&)),
21 this, SIGNAL(customContextMenuRequested(const QPoint&)));
22 Q_ASSERT(check);
23 check = connect(pModel, SIGNAL(modelReset()),
24 ui->tableView, SLOT(resizeColumnsToContents()));
25 Q_ASSERT(check);
26 setWindowTitle(tr("Wake on lan"));
27 setWindowIcon(QIcon::fromTheme("lan"));
28
29 // Sort
30 check = connect(
31 ui->tableView->horizontalHeader(),
32 &QHeaderView::sectionClicked,
33 this, [&](int c){
34 if(0 == c || 1 == c) {
35 ui->tableView->horizontalHeader()->setSortIndicatorShown(true);
36 }
37 else {
38 ui->tableView->horizontalHeader()->setSortIndicatorShown(false);
39 }
40 });
41 Q_ASSERT(check);
42 check = connect(ui->tableView->horizontalHeader(),
43 &QHeaderView::sortIndicatorChanged,
44 this, [&](int logicalIndex, Qt::SortOrder order){
45 if(0 == logicalIndex || 1 == logicalIndex)
46 ui->tableView->model()->sort(logicalIndex, order);
47 });
48 Q_ASSERT(check);
49
50 ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
51 //必须在 setModel 后,才能应用
52 /*第二个参数可以为:
53 QHeaderView::Interactive :0 用户可设置,也可被程序设置成默认大小
54 QHeaderView::Fixed :2 用户不可更改列宽
55 QHeaderView::Stretch :1 根据空间,自动改变列宽,用户与程序不能改变列宽
56 QHeaderView::ResizeToContents:3 根据内容改变列宽,用户与程序不能改变列宽
57 */
58 ui->tableView->horizontalHeader()->setSectionResizeMode(
59 QHeaderView::ResizeToContents);
60 //以下设置列宽函数必须要数据加载完成后使用,才能应用
61 //See: https://blog.csdn.net/qq_40450386/article/details/86083759
62 //ui->tableView->resizeColumnsToContents(); //设置所有列宽度自适应内容
63}
64
65CFrmWakeOnLan::~CFrmWakeOnLan()
66{
67 qDebug(log) << "CFrmWakeOnLan::~CFrmWakeOnLan()";
68 delete ui;
69}
70
71void CFrmWakeOnLan::slotRemoveRow()
72{
73 QModelIndex index = ui->tableView->currentIndex();
74 if(!index.isValid())
75 {
76 QMessageBox::information(
77 nullptr,
78 tr("Information"),
79 tr("Please select a item"));
80 return;
81 }
82
83 ui->tableView->model()->removeRow(index.row());
84}
85
86QModelIndex CFrmWakeOnLan::GetCurrentIndex()
87{
88 return ui->tableView->currentIndex();
89}
90
91QModelIndexList CFrmWakeOnLan::GetSelect()
92{
93 return ui->tableView->selectionModel()->selectedRows();
94}
95
96QToolBar* CFrmWakeOnLan::GetToolBar()
97{
98 return ui->toolBar;
99}
100
101bool CFrmWakeOnLan::eventFilter(QObject *watched, QEvent *event)
102{
103 if(ui->tableView == watched)
104 {
105 switch(event->type()){
106 case QEvent::FocusIn:
107 {
108 //qDebug(log) << Q_FUNC_INFO << event;
109 emit sigViewerFocusIn(this);
110 return false;
111 }
112 default:
113 return false;
114 }
115 }
116 return false;
117}
void sigViewerFocusIn(QWidget *pView)
The view is focus.