-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabbedwindow.cpp
More file actions
86 lines (65 loc) · 1.66 KB
/
tabbedwindow.cpp
File metadata and controls
86 lines (65 loc) · 1.66 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "tabbedwindow.h"
#include <QFont>
#include <QFontDialog>
#include <QColorDialog>
#include <QtDebug>
/* Initializes Editor with a single Window tab.
*/
TabbedWindow::TabbedWindow(QWidget *parent) : QTabWidget(parent)
{
add(new Window());
installEventFilter(this);
setMovable(true);
}
/* Adds new tab window
*/
void TabbedWindow::add(Window *tab)
{
QTabWidget::addTab(tab, tab->getFileName());
setCurrentWidget(tab);
}
/* Returns a pointer to the current Window tab of this TabbedWindow.
*/
Window* TabbedWindow::currentTab() const
{
return qobject_cast<Window*>(widget(currentIndex()));
}
/* Returns the tab at the specified index (0 to count() -1).
*/
Window* TabbedWindow::tabAt(int index) const
{
if (index < 0 || index >= count())
{
return nullptr;
}
return qobject_cast<Window*>(widget(index));
}
/* Returns a vector of all Window tabs this TabbedWindow contains.
*/
QVector<Window*> TabbedWindow::tabs() const
{
QVector<Window*> tabs;
for (int i = 0; i < count(); i++)
{
tabs.push_back(tabAt(i));
}
return tabs;
}
/* Provides user font and size dialog
*/
void TabbedWindow::promptFontSelection()
{
bool userChoseFont;
QFont newFont = QFontDialog::getFont(&userChoseFont, currentTab()->getFont(), this, tr("Choose font"));
if (!userChoseFont) return;
currentTab()->setWindowFont(newFont, QFont::Monospace, true);
}
/* Provides user color dialog
*/
void TabbedWindow::promptColorSelection()
{
QColor color = QColorDialog::getColor(Qt::black, this, tr("Choose text color"));
if (!color.isValid())
return;
currentTab()->setWindowColor(color);
}