2
/**************************************************************************
4
* Regina - A Normal Surface Theory Calculator *
7
* Copyright (c) 1999-2011, Ben Burton *
8
* For further details contact Ben Burton (bab@debian.org). *
10
* This program is free software; you can redistribute it and/or *
11
* modify it under the terms of the GNU General Public License as *
12
* published by the Free Software Foundation; either version 2 of the *
13
* License, or (at your option) any later version. *
15
* This program is distributed in the hope that it will be useful, but *
16
* WITHOUT ANY WARRANTY; without even the implied warranty of *
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
18
* General Public License for more details. *
20
* You should have received a copy of the GNU General Public *
21
* License along with this program; if not, write to the Free *
22
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
23
* MA 02110-1301, USA. *
25
**************************************************************************/
30
#include "packeteditiface.h"
31
#include "packettabui.h"
33
#include <qclipboard.h>
34
#include <qtreewidget.h>
35
#include <kapplication.h>
36
#include <ktexteditor/document.h>
37
#include <ktexteditor/view.h>
39
PacketEditTextEditor::PacketEditTextEditor(KTextEditor::View* view) :
41
connect(this, SIGNAL(sendCutToEditor()), view, SLOT(cut()));
42
connect(this, SIGNAL(sendCopyToEditor()), view, SLOT(copy()));
43
connect(this, SIGNAL(sendPasteToEditor()), view, SLOT(paste()));
45
connect(view_, SIGNAL(selectionChanged(KTextEditor::View*)),
46
this, SLOT(fireStatesChanged()));
47
connect(KApplication::kApplication()->clipboard(), SIGNAL(dataChanged()),
48
this, SLOT(fireStatesChanged()));
51
bool PacketEditTextEditor::cutEnabled() const {
52
return view_->selection() && view_->document()->isReadWrite();
55
bool PacketEditTextEditor::copyEnabled() const {
56
return view_->selection();
59
bool PacketEditTextEditor::pasteEnabled() const {
60
return (! (KApplication::kApplication()->clipboard()->text(
61
QClipboard::Clipboard).isNull())) &&
62
view_->document()->isReadWrite();
65
void PacketEditTextEditor::cut() {
66
emit sendCutToEditor();
69
void PacketEditTextEditor::copy() {
70
emit sendCopyToEditor();
73
void PacketEditTextEditor::paste() {
74
emit sendPasteToEditor();
77
PacketEditTreeWidgetSingleLine::PacketEditTreeWidgetSingleLine(
78
QTreeWidget* tree) : tree_(tree) {
79
connect(tree_, SIGNAL(itemSelectionChanged()), this,
80
SLOT(fireStatesChanged()));
83
bool PacketEditTreeWidgetSingleLine::copyEnabled() const {
84
return (! tree_->selectedItems().empty());
87
void PacketEditTreeWidgetSingleLine::copy() {
88
if (! tree_->selectedItems().empty())
89
QApplication::clipboard()->setText(
90
tree_->selectedItems().front()->text(0), QClipboard::Clipboard);
93
PacketEditTabbedUI::PacketEditTabbedUI(PacketTabbedUI* tabs) :
95
connect(tabs_->tabs, SIGNAL(currentChanged(int)),
96
this, SLOT(tabChanged(int)));
98
currentTab_ = tabs_->currentInterface();
100
if (currentTab_->getEditIface())
101
connect(currentTab_->getEditIface(), SIGNAL(statesChanged()),
102
this, SLOT(fireStatesChanged()));
105
bool PacketEditTabbedUI::cutEnabled() const {
106
if (! (currentTab_ && currentTab_->getEditIface()))
108
return currentTab_->getEditIface()->cutEnabled();
111
bool PacketEditTabbedUI::copyEnabled() const {
112
if (! (currentTab_ && currentTab_->getEditIface()))
114
return currentTab_->getEditIface()->copyEnabled();
117
bool PacketEditTabbedUI::pasteEnabled() const {
118
if (! (currentTab_ && currentTab_->getEditIface()))
120
return currentTab_->getEditIface()->pasteEnabled();
123
void PacketEditTabbedUI::cut() {
124
if (currentTab_ && currentTab_->getEditIface())
125
currentTab_->getEditIface()->cut();
128
void PacketEditTabbedUI::copy() {
129
if (currentTab_ && currentTab_->getEditIface())
130
currentTab_->getEditIface()->copy();
133
void PacketEditTabbedUI::paste() {
134
if (currentTab_ && currentTab_->getEditIface())
135
currentTab_->getEditIface()->paste();
138
void PacketEditTabbedUI::tabChanged(int newTab) {
139
if (currentTab_->getEditIface())
140
disconnect(currentTab_->getEditIface(), SIGNAL(statesChanged()),
141
this, SLOT(fireStatesChanged()));
143
currentTab_ = tabs_->interfaceAtIndex(newTab);
146
if (currentTab_->getEditIface())
147
connect(currentTab_->getEditIface(), SIGNAL(statesChanged()),
148
this, SLOT(fireStatesChanged()));