Commit 0d9420b3 authored by Robert Knight's avatar Robert Knight

Remove the frame around the session list. Use an integer instead of a string...

Remove the frame around the session list.  Use an integer instead of a string for unique session IDs internally.  Fix Monitor for Activity/Silence menu items.  Start of some experiments with colours in the session list.

svn path=/branches/work/konsole-split-view/; revision=625116
parent 212c33eb
......@@ -74,6 +74,7 @@ set(konsole_KDEINIT_SRCS
TerminalCharacterDecoder.cpp
IncrementalSearchBar.cpp
Filter.cpp
SessionListWidget.cpp
schema.cpp
konsole_wcwidth.cpp
)
......
......@@ -22,9 +22,11 @@ SessionController::SessionController(TESession* session , TEWidget* view, QObjec
, _view(view)
, _previousState(-1)
{
// handle user interface related to session (menus etc.)
setXMLFile("sessionui.rc");
setupActions();
setIdentifier(_session->sessionId());
sessionTitleChanged();
view->installEventFilter(this);
......@@ -93,12 +95,13 @@ void SessionController::setupActions()
connect( action , SIGNAL(triggered()) , this , SLOT(clearAndReset()) );
// Monitor
action = collection->addAction("monitor-activity");
action->setText( i18n("Monitor for &Activity") );
KToggleAction* toggleAction = 0;
toggleAction = new KToggleAction(i18n("Monitor for &Activity"),this);
action = collection->addAction("monitor-activity",toggleAction);
connect( action , SIGNAL(toggled(bool)) , this , SLOT(monitorActivity(bool)) );
action = collection->addAction("monitor-silence");
action->setText( i18n("Monitor for &Silence") );
toggleAction = new KToggleAction(i18n("Monitor for &Silence"),this);
action = collection->addAction("monitor-silence",toggleAction);
connect( action , SIGNAL(toggled(bool)) , this , SLOT(monitorSilence(bool)) );
// History
......@@ -173,6 +176,7 @@ void SessionController::clearHistory()
}
void SessionController::monitorActivity(bool monitor)
{
qDebug() << "Monitoring for Activity";
_session->setMonitorActivity(monitor);
}
void SessionController::monitorSilence(bool monitor)
......
// Qt
#include <QtDebug>
#include <QDrag>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMimeData>
// Konsole
#include "SessionListWidget.h"
static const char* konsoleSessionMimeFormat = "konsole/session";
SessionListWidget::SessionListWidget(QWidget* parent)
: QListWidget(parent)
{
// use large icons so that there is a big area for the user to click
// on to switch between sessions
setIconSize( QSize(32,32) );
// turn the frame off
setFrameStyle( QFrame::NoFrame );
QPalette p = palette();
p.setBrush( QPalette::Base , QColor(220,220,220) );
setPalette(p);
}
void SessionListWidget::startDrag(Qt::DropActions /*supportedActions*/)
{
qDebug() << "drag and drop started in session list widget";
QMimeData* mimeData = new QMimeData();
QByteArray data;
data.setNum(42);
mimeData->setData(konsoleSessionMimeFormat,data);
QDrag* drag = new QDrag(this);
drag->setMimeData(mimeData);
Qt::DropAction action = drag->start( Qt::MoveAction );
if ( action & Qt::MoveAction )
{
emit takeSessionEvent(currentRow());
}
}
void SessionListWidget::dragEnterEvent(QDragEnterEvent* event)
{
if ( event->mimeData()->hasFormat(konsoleSessionMimeFormat) )
{
event->accept();
}
}
void SessionListWidget::dragMoveEvent(QDragMoveEvent* event)
{
if ( event->mimeData()->hasFormat(konsoleSessionMimeFormat) )
{
event->setDropAction(Qt::MoveAction);
event->accept();
}
}
void SessionListWidget::dropEvent(QDropEvent* event)
{
if ( event->mimeData()->hasFormat(konsoleSessionMimeFormat) )
{
event->setDropAction(Qt::MoveAction);
event->accept();
emit dropSessionEvent( event->mimeData()->data(konsoleSessionMimeFormat).toInt() );
}
}
#include "SessionListWidget.moc"
#ifndef SESSIONLISTWIDGET_H
#define SESSIONLISTWIDGET_H
// Qt
#include <QListWidget>
class SessionListWidget : public QListWidget
{
Q_OBJECT
public:
SessionListWidget(QWidget* parent);
signals:
void takeSessionEvent(int itemIndex);
void dropSessionEvent(int id);
protected:
virtual void startDrag(Qt::DropActions supportedActions);
virtual void dropEvent(QDropEvent* event);
virtual void dragEnterEvent(QDragEnterEvent* event);
virtual void dragMoveEvent(QDragMoveEvent* event);
};
/*class SessionListDelegate : public QAbstractItemDelegate
{
Q_OBJECT
public:
virtual void paint(QPainter* painter , const QStyleOptionViewItem& option,
const QModelIndex& index) const;
virtual QSize sizeHint( const QStyleOptionViewItem& option,
const QModelIndex& index) const;
};*/
#endif // SESSIONLISTWIDGET_H
......@@ -265,7 +265,7 @@ private:
SessionInfo* _defaultSessionType;
typedef QPair<Source,QVariant> SourceVariant;
QHash< Setting , QList< SourceVariant > > _settings;
ColorSchemaList* _colorSchemeList;
......
......@@ -54,7 +54,7 @@
int TESession::lastSessionId = 0;
TESession::TESession() :
_shellProcess(0)
_shellProcess(0)
, _emulation(0)
, connected(true)
, monitorActivity(false)
......@@ -69,6 +69,8 @@ TESession::TESession() :
, _addToUtmp(true)
, _flowControl(true)
, _fullScripting(false)
, winId(0)
, _sessionId(0)
, zmodemBusy(false)
, zmodemProc(0)
, zmodemProgress(0)
......@@ -78,8 +80,10 @@ TESession::TESession() :
//prepare DBus communication
(void)new SessionAdaptor(this);
sessionId = QLatin1String("session") + QString::number(++lastSessionId);
QDBusConnection::sessionBus().registerObject(QLatin1String("/Sessions/")+sessionId, this);
// TODO
// numeric session identifier exposed via DBus isn't very user-friendly, but is this an issue?
_sessionId = ++lastSessionId;
QDBusConnection::sessionBus().registerObject(QLatin1String("/Sessions/session")+QString::number(_sessionId), this);
//create teletype for I/O with shell process
_shellProcess = new TEPty();
......@@ -292,7 +296,7 @@ void TESession::run()
int result = _shellProcess->run(QFile::encodeName(_program), _arguments, term.toLatin1(),
winId, _addToUtmp,
dbusService.toLatin1(),
(QLatin1String("/Sessions/") + sessionId).toLatin1());
(QLatin1String("/Sessions/") + QString::number(_sessionId)).toLatin1());
if (result < 0) { // Error in opening pseudo teletype
kWarning()<<"Unable to open a pseudo teletype!"<<endl;
QTimer::singleShot(0, this, SLOT(ptyError()));
......@@ -685,9 +689,9 @@ void TESession::setTerminalType(const QString& terminalType)
term = terminalType;
}
const QString & TESession::SessionId() const
int TESession::sessionId() const
{
return sessionId;
return _sessionId;
}
void TESession::setEncodingNo(int index)
......
......@@ -140,7 +140,7 @@ public:
*/
void setTerminalType(const QString& terminalType);
const QString& SessionId() const;
int sessionId() const;
const QString& title() const;
const QString& iconName() const;
const QString& iconText() const;
......@@ -288,6 +288,8 @@ private:
void updateTerminalSize();
int _uniqueIdentifier;
TEPty* _shellProcess;
TEmulation* _emulation;
......@@ -324,7 +326,7 @@ private:
QString term;
ulong winId;
QString sessionId;
int _sessionId;
QString cwd;
QString initial_cwd;
......@@ -342,6 +344,7 @@ private:
ColorSchema* _colorScheme;
static int lastSessionId;
};
#endif
......@@ -22,6 +22,7 @@
// Qt
#include <QHash>
#include <QLineEdit>
#include <QLinearGradient>
#include <QListWidget>
#include <QSplitter>
#include <QStackedWidget>
......@@ -40,6 +41,9 @@
#include "ViewContainer.h"
#include "ViewProperties.h"
// TODO Perhaps move everything which is Konsole-specific into different files
#include "SessionListWidget.h"
ViewContainer::~ViewContainer()
{
emit destroyed(this);
......@@ -338,9 +342,10 @@ ListViewContainer::ListViewContainer(QObject* parent)
{
_splitter = new QSplitter;
_stackWidget = new QStackedWidget(_splitter);
_listWidget = new QListWidget(_splitter);
_listWidget = new SessionListWidget(_splitter);
_listWidget->setTextElideMode( Qt::ElideLeft );
_listWidget->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
_listWidget->setDragDropMode(QAbstractItemView::DragDrop);
_splitter->addWidget(_listWidget);
_splitter->addWidget(_stackWidget);
......@@ -362,6 +367,26 @@ QWidget* ListViewContainer::activeView() const
return _stackWidget->currentWidget();
}
QBrush ListViewContainer::randomItemBackground(int r)
{
int i = r%6;
//and now for something truly unpleasant:
static const int r1[] = {255,190,190,255,190,255};
static const int r2[] = {255,180,180,255,180,255};
static const int b1[] = {190,255,190,255,255,190};
static const int b2[] = {180,255,180,255,255,180};
static const int g1[] = {190,190,255,190,255,255};
static const int g2[] = {180,180,255,180,255,255};
// hardcoded assumes item height is 32px
QLinearGradient gradient( QPoint(0,0) , QPoint(0,32) );
gradient.setColorAt(0,QColor(r1[i],g1[i],b1[i],100));
gradient.setColorAt(0.5,QColor(r2[i],g2[i],b2[i],100));
gradient.setColorAt(1,QColor(r1[i],g1[i],b1[i],100));
return QBrush(gradient);
}
void ListViewContainer::viewAdded( QWidget* view )
{
_stackWidget->addWidget(view);
......@@ -372,7 +397,9 @@ void ListViewContainer::viewAdded( QWidget* view )
item->setText( properties->title() );
item->setIcon( properties->icon() );
const int randomIndex = _listWidget->count();
item->setData( Qt::BackgroundRole , randomItemBackground(randomIndex) );
connect( properties , SIGNAL(titleChanged(ViewProperties*)) , this , SLOT(updateTitle(ViewProperties*)));
connect( properties , SIGNAL(iconChanged(ViewProperties*)) , this , SLOT(updateIcon(ViewProperties*)));
}
......
......@@ -230,6 +230,8 @@ private slots:
void updateIcon( ViewProperties* );
private:
QBrush randomItemBackground(int randomIndex);
QStackedWidget* _stackWidget;
QSplitter* _splitter;
QListWidget* _listWidget;
......
......@@ -170,7 +170,7 @@ void ViewManager::viewFocused( SessionController* controller )
_pluggedController = controller;
kDebug() << "Plugged actions for " << controller->session()->displayTitle() << endl;
//kDebug() << "Plugged actions for " << controller->session()->displayTitle() << endl;
}
}
......@@ -315,16 +315,24 @@ void ViewManager::merge(ViewManager* otherManager)
assert(view);
ViewProperties* properties = otherContainer->viewProperties(view);
otherContainer->removeView(view);
activeContainer->addView(view,properties);
// transfer the session map entries
_sessionMap.insert(view,otherManager->_sessionMap[view]);
otherManager->_sessionMap.remove(view);
takeView(otherManager,otherContainer,activeContainer,view);
}
}
void ViewManager::takeView(ViewManager* otherManager , ViewContainer* otherContainer,
ViewContainer* newContainer, TEWidget* view)
{
ViewProperties* properties = otherContainer->viewProperties(view);
otherContainer->removeView(view);
newContainer->addView(view,properties);
// transfer the session map entries
_sessionMap.insert(view,otherManager->_sessionMap[view]);
otherManager->_sessionMap.remove(view);
}
TEWidget* ViewManager::createTerminalDisplay()
{
TEWidget* display = new TEWidget(0);
......
......@@ -102,6 +102,9 @@ private:
void focusActiveView();
void registerView(TEWidget* view);
void unregisterView(TEWidget* view);
// takes a view from a view container owned by a different manager and places it in
// newContainer owned by this manager
void takeView(ViewManager* otherManager , ViewContainer* otherContainer, ViewContainer* newContainer, TEWidget* view);
ViewContainer* createContainer();
// creates a new terminal display
......
......@@ -32,13 +32,20 @@ void ViewProperties::setIcon(const QIcon& icon)
_icon = icon;
emit iconChanged(this);
}
QString ViewProperties::title()
void ViewProperties::setIdentifier(int id)
{
_id = id;
}
QString ViewProperties::title() const
{
return _title;
}
QIcon ViewProperties::icon()
QIcon ViewProperties::icon() const
{
return _icon;
}
int ViewProperties::identifier() const
{
return _id;
}
#include "ViewProperties.moc"
......@@ -40,9 +40,17 @@ public:
ViewProperties(QObject* parent) : QObject(parent) {}
/** Returns the icon associated with a view */
QIcon icon();
QIcon icon() const;
/** Returns the title associated with a view */
QString title();
QString title() const;
/**
* A unique identifier representing the data displayed by the view associated with this
* ViewProperties instance.
*
* This can be used when dragging and dropping views between windows so that
*/
int identifier() const;
signals:
/** Emitted when the icon for a view changes */
......@@ -61,10 +69,15 @@ protected:
* an iconChanged() signal to be emitted
*/
void setIcon(const QIcon& icon);
/**
* Subclasses may call this method to change the identifier.
*/
void setIdentifier(int id);
private:
QIcon _icon;
QString _title;
int _id;
};
#endif //VIEWPROPERTIES_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment