]>
cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kitemlistroleeditor.cpp
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "kitemlistroleeditor.h"
25 KItemListRoleEditor::KItemListRoleEditor(QWidget
*parent
) :
30 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
31 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
32 document()->setDocumentMargin(0);
35 parent
->installEventFilter(this);
39 KItemListRoleEditor::~KItemListRoleEditor()
43 void KItemListRoleEditor::setIndex(int index
)
48 int KItemListRoleEditor::index() const
53 void KItemListRoleEditor::setRole(const QByteArray
& role
)
58 QByteArray
KItemListRoleEditor::role() const
63 bool KItemListRoleEditor::eventFilter(QObject
* watched
, QEvent
* event
)
65 if (watched
== parentWidget() && event
->type() == QEvent::Resize
) {
69 return KTextEdit::eventFilter(watched
, event
);
72 bool KItemListRoleEditor::event(QEvent
* event
)
74 if (event
->type() == QEvent::FocusOut
) {
75 emit
roleEditingFinished(m_index
, m_role
, toPlainText());
77 return KTextEdit::event(event
);
80 void KItemListRoleEditor::keyPressEvent(QKeyEvent
* event
)
82 switch (event
->key()) {
84 emit
roleEditingCanceled(m_index
, m_role
, toPlainText());
89 emit
roleEditingFinished(m_index
, m_role
, toPlainText());
96 KTextEdit::keyPressEvent(event
);
100 void KItemListRoleEditor::autoAdjustSize()
102 const qreal requiredWidth
= document()->size().width();
103 const qreal availableWidth
= size().width() - 2 * frameWidth();
104 if (requiredWidth
> availableWidth
) {
105 qreal newWidth
= requiredWidth
+ 2 * frameWidth();
106 if (parentWidget() && pos().x() + newWidth
> parentWidget()->width()) {
107 newWidth
= parentWidget()->width() - pos().x();
109 resize(newWidth
, size().height());
113 #include "kitemlistroleeditor.moc"