Commit 9bc042e0 authored by Thomas Hartmann's avatar Thomas Hartmann Committed by hjk
Browse files

WelcomePage: Add tooltip for sessions



The tooltip allows renaming, cloning and deleting and shows
included projects.

The following method was added to Session:

QStringList projectsForSessionName(const QString &session) const;

I moved the SessionNameInputDialog into the header to reuse it.

I added new roles to SessionModel (ProjectsPathRole, ProjectsDisplayRole).
The following slots were added to SessionModel to expose the backend
functionality:

void cloneSession(const QString &session);
void deleteSession(const QString &session);
void renameSession(const QString &session);

Change-Id: I0182a26dc63b4f051ea948756decd5413c832c60
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 7e380e9d
......@@ -64,22 +64,6 @@ Rectangle {
anchors.top: parent.top
anchors.topMargin: 0
RecentSessions {
id: recentSessions
x: 87
y: 144
width: 274
anchors.left: recentlyUsedSessions.left
anchors.right: recentlyUsedProjects.left
anchors.rightMargin: 40
anchors.top: recentlyUsedSessions.bottom
anchors.topMargin: 20
model: sessionList
}
Rectangle {
width: 1
height: line.height
......@@ -94,7 +78,7 @@ Rectangle {
x: 406
y: 144
width: 481
height: 416
height: 432
id: recentProjects
anchors.left: recentlyUsedProjects.left
......@@ -184,5 +168,21 @@ Rectangle {
source: "widgets/images/icons/createIcon.png"
}
}
RecentSessions {
id: recentSessions
x: 87
y: 144
width: 274
anchors.left: recentlyUsedSessions.left
anchors.right: recentlyUsedProjects.left
anchors.rightMargin: 40
anchors.top: recentlyUsedSessions.bottom
anchors.topMargin: 20
model: sessionList
}
}
}
......@@ -37,6 +37,7 @@ QtObject {
property alias standardCaption: standardCaptionText.font
property alias standstandardDescription: standardDescriptionText.font
property alias italicDescription: italicDescriptionText.font
property alias boldDescription: boldText.font
property list<Item> texts: [
......@@ -50,6 +51,16 @@ QtObject {
font.family: "Helvetica"
},
Text {
id: boldText
visible: false
font.pixelSize: 13
font.bold: true
font.family: "Helvetica"
},
Text {
id: standardCaptionText
......
......@@ -47,6 +47,7 @@ Text {
property bool active: false
property bool hovered: mouseArea.state === "hovered"
onActiveChanged: {
if (active)
mouseArea.state = ""
......
......@@ -33,58 +33,306 @@
import QtQuick 1.0
import qtcomponents 1.0
ListView {
id: root
Item {
property alias model: root.model
height: Math.min(root.count * root.delegateHeight, 276)
height: Math.min(count * delegateHeight, 276)
snapMode: ListView.SnapToItem
property int delegateHeight: currentItem.height + spacing
ListView {
id: root
clip: true
interactive: false
anchors.fill: parent
snapMode: ListView.SnapToItem
property int delegateHeight: currentItem.height + spacing
clip: true
interactive: false
spacing: 4
spacing: 4
delegate: SessionItem {
id: item
property bool delayedHide: false
function fullSessionName()
{
var newSessionName = sessionName
if (model.lastSession && sessionList.isDefaultVirgin())
newSessionName = qsTr("%1 (last session)").arg(sessionName);
else if (model.activeSession && !sessionList.isDefaultVirgin())
newSessionName = qsTr("%1 (current session)").arg(sessionName);
return newSessionName;
Behavior on delayedHide {
PropertyAnimation { duration: 200; }
}
name: fullSessionName()
}
onDelayedHideChanged: {
panel.opacity = 0;
}
WheelArea {
id: wheelarea
anchors.fill: parent
verticalMinimumValue: vscrollbar.minimumValue
verticalMaximumValue: vscrollbar.maximumValue
delegate: SessionItem {
id: item
onVerticalValueChanged: root.contentY = Math.round(verticalValue / delegateHeight) * delegateHeight
property bool activate: hovered
Behavior on activate {
PropertyAnimation { duration: 50 }
}
onActivateChanged: {
if (activate) {
panel.y = item.y + 20 - root.contentY;
panel.opacity = 1;
panel.projectsPathList = projectsPath;
panel.projectsDisplayList = projectsName
panel.currentSession = sessionName;
} else {
if (!panel.hovered)
panel.opacity = 0
}
}
onClicked: {
root.delayedHide = !root.delayedHide
}
function fullSessionName()
{
var newSessionName = sessionName
if (model.lastSession && sessionList.isDefaultVirgin())
newSessionName = qsTr("%1 (last session)").arg(sessionName);
else if (model.activeSession && !sessionList.isDefaultVirgin())
newSessionName = qsTr("%1 (current session)").arg(sessionName);
return newSessionName;
}
name: fullSessionName()
}
WheelArea {
id: wheelarea
anchors.fill: parent
verticalMinimumValue: vscrollbar.minimumValue
verticalMaximumValue: vscrollbar.maximumValue
onVerticalValueChanged: root.contentY = Math.round(verticalValue / root.delegateHeight) * root.delegateHeight
}
ScrollBar {
id: vscrollbar
orientation: Qt.Vertical
property int availableHeight : root.height
visible: root.contentHeight > availableHeight
maximumValue: root.contentHeight > availableHeight ? root.contentHeight - availableHeight : 0
minimumValue: 0
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
singleStep: root.delegateHeight
anchors.topMargin: styleitem.style == "mac" ? 1 : 0
onValueChanged: root.contentY = Math.round(value / root.delegateHeight) * root.delegateHeight
anchors.rightMargin: styleitem.frameoffset
anchors.bottomMargin: styleitem.frameoffset
}
}
ScrollBar {
id: vscrollbar
orientation: Qt.Vertical
property int availableHeight : root.height
visible: contentHeight > availableHeight
maximumValue: contentHeight > availableHeight ? root.contentHeight - availableHeight : 0
minimumValue: 0
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
singleStep: delegateHeight
anchors.topMargin: styleitem.style == "mac" ? 1 : 0
onValueChanged: root.contentY = Math.round(value / delegateHeight) * delegateHeight
anchors.rightMargin: styleitem.frameoffset
anchors.bottomMargin: styleitem.frameoffset
Rectangle {
CustomFonts {
id: fonts
}
id: panel
border.width: 1
smooth: true
opacity: 0
property int margin: 12
width: panelColumn.width + margin * 2
height: panelColumn.height + margin * 2
property bool hovered: false
property variant projectsPathList
property variant projectsDisplayList
property string currentSession
onHoveredChanged: {
if (panel.hovered)
panel.opacity = 1;
else
panel.opacity = 0;
}
MouseArea {
anchors.topMargin: 0
anchors.fill: parent
id: panelMouseArea
hoverEnabled: true
onEntered: {
panel.hovered = true
}
onExited: {
panel.hovered = false
}
}
Column {
x: panel.margin
y: panel.margin
id: panelColumn
spacing: 8
Repeater {
model: panel.projectsPathList
delegate: Row {
spacing: 6
Text {
text: panel.projectsDisplayList[index]
font: fonts.boldDescription
}
Text {
text: modelData
font: fonts.linkFont
}
}
}
Row {
x: -2
spacing: 2
id: add
Item {
//place hold for an icon
width: 16
height: 16
MouseArea {
id: exitMouseArea
anchors.fill: parent
hoverEnabled: true
onEntered: {
panel.hovered = true
}
onExited: {
panel.hovered = false
}
onClicked: {
//Will be uncommented once we have an icon
//model.cloneSession(panel.currentSession);
}
}
}
LinkedText {
text: qsTr("Clone this session")
onEntered: {
panel.hovered = true
}
onExited: {
panel.hovered = false
}
onClicked: {
panel.opacity = 0;
model.cloneSession(panel.currentSession);
}
}
}
Row {
x: -2
spacing: 2
id: clear
Item {
//place holder for an icon
width: 16
height: 16
MouseArea {
id: clearMouseArea
anchors.fill: parent
hoverEnabled: true
onEntered: {
panel.hovered = true
}
onExited: {
panel.hovered = false
}
onClicked: {
//Will be uncommented once we have an icon
//model.deleteSession(panel.currentSession);
}
}
}
LinkedText {
text: qsTr("Delete this session")
onEntered: {
panel.hovered = true
}
onExited: {
panel.hovered = false
}
onClicked: {
panel.opacity = 0;
model.deleteSession(panel.currentSession);
}
}
}
Row {
x: -2
spacing: 2
id: rename
Item {
//place holder for an icon
opacity: clearMouseArea.containsMouse ? 0.8 : 1
Behavior on opacity {
PropertyAnimation { duration: visible ? 0 : 50; }
}
width: 16
height: 16
MouseArea {
id: renameMouseArea
anchors.fill: parent
hoverEnabled: true
onEntered: {
panel.hovered = true
}
onExited: {
panel.hovered = false
}
onClicked: {
//Will be uncommented once we have an icon
//model.renameSession(panel.currentSession);
}
}
}
LinkedText {
text: qsTr("Rename this session")
onEntered: {
panel.hovered = true
}
onExited: {
panel.hovered = false
}
onClicked: {
panel.opacity = 0;
model.renameSession(panel.currentSession);
}
}
}
}
Behavior on opacity {
PropertyAnimation { duration: visible ? 50 : 100; }
}
radius: 2
gradient: Gradient {
GradientStop {
position: 0.00;
color: "#ffffff";
}
GradientStop {
position: 1.00;
color: "#e4e5f0";
}
}
}
}
......@@ -35,6 +35,13 @@ import QtQuick 1.1
Row {
spacing: 4
property alias name: sessionText.text
property alias hovered: sessionText.hovered
signal clicked
id: root
Image {
source: "images/bullet.png"
anchors.verticalCenter: sessionText.verticalCenter
......@@ -42,6 +49,9 @@ Row {
LinkedText {
id: sessionText
onClicked: projectWelcomePage.requestSession(sessionName)
onClicked: {
projectWelcomePage.requestSession(sessionName);
root.clicked();
}
}
}
......@@ -36,9 +36,12 @@
#include <QDeclarativeEngine>
#include <QDeclarativeContext>
#include <QFileInfo>
#include <QDir>
#include <projectexplorer/session.h>
#include <projectexplorer/projectexplorer.h>
#include <sessiondialog.h>
namespace ProjectExplorer {
namespace Internal {
......@@ -51,6 +54,8 @@ SessionModel::SessionModel(SessionManager *manager, QObject *parent)
roleNames[DefaultSessionRole] = "defaultSession";
roleNames[ActiveSessionRole] = "activeSession";
roleNames[LastSessionRole] = "lastSession";
roleNames[ProjectsPathRole] = "projectsPath";
roleNames[ProjectsDisplayRole] = "projectsName";
setRoleNames(roleNames);
connect(manager, SIGNAL(sessionLoaded(QString)), SLOT(resetSessions()));
}
......@@ -60,10 +65,28 @@ int SessionModel::rowCount(const QModelIndex &) const
return m_manager->sessions().count();
}
QStringList pathsToBaseNames(const QStringList &paths)
{
QStringList stringList;
foreach (const QString &path, paths)
stringList.append(QFileInfo(path).completeBaseName());
return stringList;
}
QStringList pathsWithTildeHomePath(const QStringList &paths)
{
QStringList stringList;
foreach (const QString &path, paths)
stringList.append(Utils::withTildeHomePath(QDir::toNativeSeparators(path)));
return stringList;
}
QVariant SessionModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole || role == DefaultSessionRole ||
role == LastSessionRole || role == ActiveSessionRole) {
role == LastSessionRole || role == ActiveSessionRole || role == ProjectsPathRole || role == ProjectsDisplayRole) {
QString sessionName = m_manager->sessions().at(index.row());
if (role == Qt::DisplayRole)
return sessionName;
......@@ -73,6 +96,10 @@ QVariant SessionModel::data(const QModelIndex &index, int role) const
return m_manager->lastSession() == sessionName;
else if (role == ActiveSessionRole)
return m_manager->activeSession() == sessionName;
else if (role == ProjectsPathRole)
return pathsWithTildeHomePath(m_manager->projectsForSessionName(sessionName));
else if (role == ProjectsDisplayRole)
return pathsToBaseNames(m_manager->projectsForSessionName(sessionName));
}
return QVariant();
}
......@@ -87,6 +114,49 @@ void SessionModel::resetSessions()
reset();
}
void SessionModel::cloneSession(const QString &session)
{
SessionNameInputDialog newSessionInputDialog(m_manager->sessions(), 0);
newSessionInputDialog.setWindowTitle(tr("New session name"));
newSessionInputDialog.setValue(session + QLatin1String(" (2)"));
if (newSessionInputDialog.exec() == QDialog::Accepted) {
QString newSession = newSessionInputDialog.value();
if (newSession.isEmpty() || m_manager->sessions().contains(newSession))
return;
m_manager->cloneSession(session, newSession);
reset();
if (newSessionInputDialog.isSwitchToRequested()) {
m_manager->loadSession(newSession);
}
}
}
void SessionModel::deleteSession(const QString &session)
{
m_manager->deleteSession(session);
reset();
}
void SessionModel::renameSession(const QString &session)
{
SessionNameInputDialog newSessionInputDialog(m_manager->sessions(), 0);
newSessionInputDialog.setWindowTitle(tr("New session name"));
newSessionInputDialog.setValue(session);
if (newSessionInputDialog.exec() == QDialog::Accepted) {
QString newSession = newSessionInputDialog.value();
if (newSession.isEmpty() || m_manager->sessions().contains(newSession))
return;
m_manager->renameSession(session, newSession);
reset();
if (newSessionInputDialog.isSwitchToRequested()) {
m_manager->loadSession(newSession);
}
}
}
ProjectModel::ProjectModel(ProjectExplorerPlugin *plugin, QObject *parent)
: QAbstractListModel(parent), m_plugin(plugin)
......
......@@ -54,7 +54,7 @@ class SessionModel : public QAbstractListModel
{
Q_OBJECT
public:
enum { DefaultSessionRole = Qt::UserRole+1, LastSessionRole, ActiveSessionRole };
enum { DefaultSessionRole = Qt::UserRole+1, LastSessionRole, ActiveSessionRole, ProjectsPathRole, ProjectsDisplayRole };
SessionModel(SessionManager* manager, QObject* parent = 0);
int rowCount(const QModelIndex &parent) const;
......@@ -64,6 +64,9 @@ public:
public slots:
void resetSessions();
void cloneSession(const QString &session);
void deleteSession(const QString &session);
void renameSession(const QString &session);
private:
SessionManager *m_manager;
......
......@@ -914,3 +914,16 @@ void SessionManager::sessionLoadingProgress()
m_future.setProgressValue(m_future.progressValue() + 1);
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}
QStringList ProjectExplorer::SessionManager::projectsForSessionName(<