-
Notifications
You must be signed in to change notification settings - Fork 0
/
katetabbar.cpp
127 lines (104 loc) · 2.86 KB
/
katetabbar.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* This file is part of the KDE project
Copyright (C) 2008 Javier Goday <jgoday @ gmail.com>
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 "katetabbar.h"
#include <KIcon>
#include <KIconLoader>
#include <KIO/NetAccess>
#include <KParts/Part>
#include <KTextEditor/Document>
KateTabBar::KateTabBar(QWidget *parent)
: KTabBar(parent),
m_documents(),
m_keys(),
m_position(0)
{
setShape(QTabBar::RoundedSouth);
setCloseButtonEnabled(true);
}
KateTabBar::~KateTabBar()
{
}
KTextEditor::Document *KateTabBar::documentFromIndex(int index)
{
return m_documents [index];
}
int KateTabBar::shapeAsInt()
{
switch(shape()) {
case QTabBar::RoundedNorth:
return 0;
break;
default:
return 1;
};
}
int KateTabBar::position()
{
return m_position;
}
void KateTabBar::addDocument(KTextEditor::Document *document)
{
int key = addTab(document->documentName());
m_documents [key] = document;
m_keys [document] = key;
connect(document, SIGNAL(documentNameChanged(KTextEditor::Document *)),
SLOT(slotDocumentChange(KTextEditor::Document *)));
connect(document, SIGNAL(modifiedChanged(KTextEditor::Document *)),
SLOT(slotDocumentChange(KTextEditor::Document *)));
}
void KateTabBar::removeDocument(KTextEditor::Document *document)
{
int key = m_keys [document];
m_documents.remove(key);
m_keys.remove(document);
foreach(int i, m_documents.keys()) {
if (i > key) {
KTextEditor::Document *doc = m_documents [i];
m_documents.remove(i);
m_keys.remove(doc);
m_documents [i-1] = doc;
m_keys [doc] = i-1;
}
}
removeTab(key);
}
void KateTabBar::activateDocument(KTextEditor::Document *document)
{
int key = m_keys [document];
setCurrentIndex(key);
}
void KateTabBar::setShapeAsInt(int shape)
{
switch(shape) {
case QTabBar::RoundedNorth:
setShape(QTabBar::RoundedNorth);
break;
default:
setShape(QTabBar::RoundedSouth);
break;
};
}
void KateTabBar::setPosition(int position)
{
m_position = position;
}
void KateTabBar::slotDocumentChange(KTextEditor::Document *document)
{
int key = m_keys [document];
// sets the icon
setTabIcon(key, KIcon(KIO::pixmapForUrl(document->url(), 0, KIconLoader::Desktop, 16)));
if(document->isModified()) {
setTabText(key, document->documentName() + " *");
setTabTextColor(key, Qt::red);
}
else {
setTabText(key, document->documentName());
setTabTextColor(key, Qt::black);
}
}
#include "katetabbar.moc"