Konsole
ProfileListWidget.cpp
Go to the documentation of this file.00001 /* 00002 Copyright 2006-2008 by Robert Knight <robertknight@gmail.com> 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301 USA. 00018 */ 00019 00020 // Own 00021 #include "ProfileListWidget.h" 00022 00023 // Qt 00024 #include <KDebug> 00025 #include <QtGui/QDrag> 00026 #include <QtGui/QKeyEvent> 00027 #include <QtCore/QMimeData> 00028 00029 static const char* konsoleSessionMimeFormat = "konsole/session"; 00030 00031 ProfileListWidget::ProfileListWidget(QWidget* parent) 00032 : QListWidget(parent) 00033 { 00034 // use large icons so that there is a big area for the user to click 00035 // on to switch between sessions 00036 setIconSize( QSize(32,32) ); 00037 00038 // turn the frame off 00039 setFrameStyle( QFrame::NoFrame ); 00040 00041 QPalette p = palette(); 00042 p.setBrush( QPalette::Base , QColor(220,220,220) ); 00043 setPalette(p); 00044 } 00045 00046 void ProfileListWidget::startDrag(Qt::DropActions /*supportedActions*/) 00047 { 00048 kDebug() << "drag and drop started in session list widget"; 00049 00050 QMimeData* mimeData = new QMimeData(); 00051 00052 QByteArray data; 00053 data.setNum(42); 00054 mimeData->setData(konsoleSessionMimeFormat,data); 00055 00056 QDrag* drag = new QDrag(this); 00057 drag->setMimeData(mimeData); 00058 00059 Qt::DropAction action = drag->start( Qt::MoveAction ); 00060 00061 if ( action & Qt::MoveAction ) 00062 { 00063 emit takeSessionEvent(currentRow()); 00064 } 00065 } 00066 00067 void ProfileListWidget::dragEnterEvent(QDragEnterEvent* event) 00068 { 00069 if ( event->mimeData()->hasFormat(konsoleSessionMimeFormat) ) 00070 { 00071 event->accept(); 00072 } 00073 } 00074 00075 void ProfileListWidget::dragMoveEvent(QDragMoveEvent* event) 00076 { 00077 if ( event->mimeData()->hasFormat(konsoleSessionMimeFormat) ) 00078 { 00079 event->setDropAction(Qt::MoveAction); 00080 event->accept(); 00081 } 00082 } 00083 00084 void ProfileListWidget::dropEvent(QDropEvent* event) 00085 { 00086 if ( event->mimeData()->hasFormat(konsoleSessionMimeFormat) ) 00087 { 00088 event->setDropAction(Qt::MoveAction); 00089 event->accept(); 00090 00091 emit dropSessionEvent( event->mimeData()->data(konsoleSessionMimeFormat).toInt() ); 00092 } 00093 } 00094 00095 00096 #include "ProfileListWidget.moc"