blob: 024093af39a410254ad5e48735f8f1a6578b486f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version
2 of the License, or (at your option) any later version.
*/
#include <QAction>
#include <QActionGroup>
#include <QHeaderView>
#include <QMenu>
#include <QContextMenuEvent>
#include <QSettings>
#include <QApplication>
#include "smtreeview.h"
#include "smglobals.h"
SmTreeView::SmTreeView(QWidget *parent) : QTreeView(parent) {
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
setAlternatingRowColors(true);
setPalette(qApp->palette());
}
SmTreeView::SmTreeView(const QString &hSetting, QWidget *parent) : QTreeView(parent), mHeaderSetting(hSetting){
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
setAlternatingRowColors(true);
setPalette(qApp->palette());
}
void SmTreeView::readHeaderConfig(){
QSettings s;
QByteArray headerPos = s.value(mHeaderSetting).toByteArray();
if(!headerPos.isEmpty()){
header()->restoreState(headerPos);
}
}
void SmTreeView::writeHeaderConfig(){
QSettings s;
s.setValue(mHeaderSetting, header()->saveState());
}
void SmTreeView::toggleHeader(QObject *action){
QAction *a = qobject_cast<QAction*>(action);
int logicalIndex = a->data().toInt();
QHeaderView *hv = header();
hv->setSectionHidden(logicalIndex, !a->isChecked());
}
void SmTreeView::contextMenuEvent(QContextMenuEvent *e){
if(actions().isEmpty()){
return;
}
QMenu contextMenu(this);
foreach(QAction *a, actions()){
contextMenu.addAction(a);
}
contextMenu.exec(e->globalPos());
}
|