# HG changeset patch # User Goffi # Date 1314211135 -7200 # Node ID c63d67895cbe3681ec6929a7c453b8d364b22e0b # Parent 017925589d4cacae33da493fd7791f1af821f7f0 layout designer: first draft diff -r 017925589d4c -r c63d67895cbe bellaciao.pro --- a/bellaciao.pro Sun Aug 14 18:03:54 2011 +0200 +++ b/bellaciao.pro Wed Aug 24 20:38:55 2011 +0200 @@ -10,6 +10,6 @@ CONFIG += debug # Input -HEADERS += bellaciao.h contact_list.h dbus_bridge.h dbus_types.h bridge.h settings.h session.h contact.h jid.h -SOURCES += main.cpp bellaciao.cpp contact_list.cpp dbus_bridge.cpp dbus_types.cpp bridge.cpp settings.cpp session.cpp contact.cpp jid.cpp -FORMS += main_win.ui settings.ui +HEADERS += bellaciao.h contact_list.h dbus_bridge.h dbus_types.h bridge.h settings.h session.h contact.h jid.h layout_designer.h layout_builder.h layout_widget.h layout_view.h +SOURCES += main.cpp bellaciao.cpp contact_list.cpp dbus_bridge.cpp dbus_types.cpp bridge.cpp settings.cpp session.cpp contact.cpp jid.cpp layout_designer.cpp layout_builder.cpp layout_widget.cpp layout_view.cpp +FORMS += main_win.ui settings.ui layout_designer.ui layout_builder.ui diff -r 017925589d4c -r c63d67895cbe layout_builder.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/layout_builder.cpp Wed Aug 24 20:38:55 2011 +0200 @@ -0,0 +1,72 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#include "layout_builder.h" + + +LayoutBuilder::LayoutBuilder(QWidget* parent) + : QWidget(parent) +{ + setupUi(this); + LayoutWidgetModel* model = new LayoutWidgetModel(this); + widgetsList->setModel(model); +} + +LayoutBuilder::~LayoutBuilder() +{ + qDebug() << "Destructeur de LayoutBuilder"; +} + +const QHash& LayoutBuilder::getLayoutWidgetsDict() +{ + return dynamic_cast(widgetsList->model())->getLayoutWidgetsDict(); +} + +void LayoutBuilder::addWidget(LayoutWidget* widget) +{ + dynamic_cast(widgetsList->model())->append(widget); +} + +LayoutBuilderContactList::LayoutBuilderContactList(QWidget* parent) + : LayoutBuilder(parent) +{ + qDebug() << "constructeur de LayoutBuilderContactList"; + addWidget(new LayoutWidget("List")); + addWidget(new LayoutWidget("Box")); + layoutView->setLayoutWidgets(getLayoutWidgetsDict()); +} + +LayoutBuilderContactList::~LayoutBuilderContactList() +{ + qDebug() << "Destructeur de LayoutBuilderContactList"; +} + +LayoutBuilder* LayoutBuilderFactory::Create(LayoutType type, QWidget* parent) +{ + switch (type) { + case CONTACT_LIST: + return new LayoutBuilderContactList(parent); + break; + case CONTACT_ITEM: + break; + default: + qCritical() << "Unknwon LayoutBuilder type"; + } + + return 0; +} diff -r 017925589d4c -r c63d67895cbe layout_builder.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/layout_builder.h Wed Aug 24 20:38:55 2011 +0200 @@ -0,0 +1,64 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#ifndef LAYOUT_BUILDER_H +#define LAYOUT_BUILDER_H + + +#include +#include "ui_layout_builder.h" +#include "layout_widget.h" + +typedef enum +{ + CONTACT_LIST, CONTACT_ITEM +} LayoutType; + +class LayoutBuilder : public QWidget, protected Ui::LayoutBuilderUI +{ + Q_OBJECT + + public: + LayoutBuilder(QWidget* parent=0); + virtual ~LayoutBuilder(); + const QHash& getLayoutWidgetsDict(); + + protected: + void addWidget(LayoutWidget* widget); + +}; + +class LayoutBuilderContactList : public LayoutBuilder +{ + Q_OBJECT + + public: + LayoutBuilderContactList(QWidget* parent=0); + ~LayoutBuilderContactList(); +}; + +class LayoutBuilderFactory +{ + public: + LayoutBuilder* Create(LayoutType type=CONTACT_ITEM, QWidget* parent=0); + +}; + + + +#endif diff -r 017925589d4c -r c63d67895cbe layout_builder.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/layout_builder.ui Wed Aug 24 20:38:55 2011 +0200 @@ -0,0 +1,128 @@ + + + LayoutBuilderUI + + + + 0 + 0 + 456 + 495 + + + + Form + + + + + + QFrame::Plain + + + Qt::Horizontal + + + false + + + + + 250 + 16777215 + + + + Widgets + + + false + + + false + + + + + + true + + + QAbstractItemView::DragOnly + + + + + + + + + 150 + 0 + + + + + + + Qt::Vertical + + + + + 0 + 150 + + + + true + + + + + 0 + 0 + 181 + 144 + + + + + + + + + + + + + 0 + 150 + + + + Properties + + + false + + + + + + + + + + + + + LayoutView + QWidget +
layout_view.h
+ 1 +
+
+ + +
diff -r 017925589d4c -r c63d67895cbe layout_builder_widgets.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/layout_builder_widgets.cpp Wed Aug 24 20:38:55 2011 +0200 @@ -0,0 +1,47 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#include "layout_widgets.h" +#include + +WidgetProperty::WidgetProperty(const QString& name, const QString& tooltip) + : m_name(name), m_type(NONE) +{ +} + +WidgetProperty::~WidgetProperty() +{ +} + +WidgetPropertyBool::WidgetPropertyBool(const QString& name, bool checked, const QString& tooltip) + : WidgetProperty(name, tooltip), m_checked(checked), m_type(BOOL) +{ +} + +LayoutWidget::LayoutWidget(const QString& name, const QString& icon) + : m_name(name), m_icon(icon) +{ + qDebug() << "LayoutWidget constructeur (" << name <<")"; + +} + +LayoutWidget::~LayoutWidget() +{ + qDebug() << "LayoutWidget destructeur"; + +} diff -r 017925589d4c -r c63d67895cbe layout_designer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/layout_designer.cpp Wed Aug 24 20:38:55 2011 +0200 @@ -0,0 +1,31 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#include "layout_designer.h" + +LayoutDesigner::LayoutDesigner(QWidget* parent) + : QWidget(parent) +{ + setupUi(this); + centralTabs->addTab(layoutBuilder_factory.Create(CONTACT_LIST), tr("Contact list")); +} + +LayoutDesigner::~LayoutDesigner() +{ + qDebug() << "Destructeur de LayoutDesigner"; +} diff -r 017925589d4c -r c63d67895cbe layout_designer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/layout_designer.h Wed Aug 24 20:38:55 2011 +0200 @@ -0,0 +1,40 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#ifndef LAYOUT_DESIGNER_H +#define LAYOUT_DESIGNER_H + + +#include +#include "ui_layout_designer.h" +#include "layout_builder.h" + +class LayoutDesigner : public QWidget, private Ui::LayoutDesignerUI +{ + Q_OBJECT + + public: + LayoutDesigner(QWidget* parent=0); + ~LayoutDesigner(); + + private: + LayoutBuilderFactory layoutBuilder_factory; + +}; + +#endif diff -r 017925589d4c -r c63d67895cbe layout_designer.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/layout_designer.ui Wed Aug 24 20:38:55 2011 +0200 @@ -0,0 +1,54 @@ + + + LayoutDesignerUI + + + + 0 + 0 + 402 + 425 + + + + Form + + + + + + QTabWidget::South + + + QTabWidget::Rounded + + + -1 + + + + + + + + + + New contact layout + + + + + + + Delete layout + + + + + + + + + + + diff -r 017925589d4c -r c63d67895cbe layout_view.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/layout_view.cpp Wed Aug 24 20:38:55 2011 +0200 @@ -0,0 +1,81 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +#include "layout_view.h" +#include + +LayoutView::LayoutView(QWidget* parent) +{ + setAcceptDrops(true); + m_layout = new QVBoxLayout; + setLayout(m_layout); + m_layout->addStretch(); + setStyleSheet("QLabel {border: 1px solid black; \ + border-radius: 5px; \ + text-align: center; \ + background-color: white; \ + min-height: 20px; \ + max-height: 20px; \ + margin: 2px; \ + }"); +} + +LayoutView::~LayoutView() +{ +} + +void LayoutView::setLayoutWidgets(const QHash& layout_widgets) +{ + m_layout_widgets = layout_widgets; +} + +void LayoutView::dragEnterEvent (QDragEnterEvent* event ) +{ + qDebug() << "Drag enter: " << event->pos(); + if (event->mimeData()->hasFormat(LAYOUT_WIDGET_MIME)) + event->acceptProposedAction(); +} + +void LayoutView::dragMoveEvent (QDragMoveEvent* event ) +{ + qDebug() << "Drag move: " << event->pos(); + QWidget* _wid = childAt(event->pos()); + if (_wid) + qDebug() << "Object: " << _wid->metaObject()->className(); +} + +void LayoutView::dropEvent (QDropEvent* event) +{ + const QMimeData *data = event->mimeData(); + QByteArray encodedData = data->data(LAYOUT_WIDGET_MIME); + QDataStream stream(&encodedData, QIODevice::ReadOnly); + while (!stream.atEnd()) { + QString widget_name; + stream >> widget_name; + addWidget(widget_name); + } +} + +void LayoutView::addWidget(const QString& name) +{ + LayoutWidget* _widget = m_layout_widgets[name]; + qDebug() << "Adding: " << name; + QLabel* _label = new QLabel(name); + _label->setAlignment(Qt::AlignCenter); + m_layout->insertWidget(qMax(0, m_layout->count()-1), _label, 0, Qt::AlignTop); + +} diff -r 017925589d4c -r c63d67895cbe layout_view.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/layout_view.h Wed Aug 24 20:38:55 2011 +0200 @@ -0,0 +1,47 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#ifndef LAYOUT_VIEW_H +#define LAYOUT_VIEW_H + +#include +#include +#include "layout_widget.h" + +#define LAYOUT_WIDGET_MIME "application/x-bellaciao-widget" + + +class LayoutView : public QWidget +{ + Q_OBJECT + + public: + LayoutView(QWidget* parent=0); + ~LayoutView(); + void setLayoutWidgets(const QHash& layout_widgets); + void dragEnterEvent (QDragEnterEvent* event ); + void dragMoveEvent (QDragMoveEvent* event ); + void dropEvent (QDropEvent * event); + protected: + void addWidget(const QString& name); + private: + QHash m_layout_widgets; + QList m_widgets_list; + QVBoxLayout* m_layout; +}; +#endif diff -r 017925589d4c -r c63d67895cbe layout_widget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/layout_widget.cpp Wed Aug 24 20:38:55 2011 +0200 @@ -0,0 +1,140 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#include "layout_widget.h" + +WidgetProperty::WidgetProperty(const QString& name, const QString& tooltip) + : m_name(name), m_type(NONE) +{ +} + +WidgetPropertyBool::WidgetPropertyBool(const QString& name, bool checked, const QString& tooltip) + : WidgetProperty(name, tooltip), m_checked(checked) +{ + m_type = BOOL; +} + +LayoutWidget::LayoutWidget(const QString& name, const QString& icon) + : m_name(name), m_icon(icon) +{ + qDebug() << "LayoutWidget constructeur (" << name <<")"; + +} + +LayoutWidget::~LayoutWidget() +{ + qDebug() << "LayoutWidget destructeur"; + +} + +const QString& LayoutWidget::getName() const +{ + return m_name; +} + +LayoutWidgetModel::LayoutWidgetModel(QObject* parent) + : QAbstractListModel(parent) +{ +} + +LayoutWidgetModel::~LayoutWidgetModel() +{ + + qDebug() << "Destructeur de LayoutWidgetModel"; + while (!m_layout_widgets.isEmpty()) + delete m_layout_widgets.takeFirst(); + qDebug() << "Fin Destructeur de LayoutWidgetModel"; +} + +int LayoutWidgetModel::rowCount(const QModelIndex &parent) const +{ + return m_layout_widgets.size(); +} + +QVariant LayoutWidgetModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() >= m_layout_widgets.size()) + return QVariant(); + + if (role == Qt::DisplayRole) + return m_layout_widgets[index.row()]->getName(); + + return QVariant(); +} + +Qt::ItemFlags LayoutWidgetModel::flags (const QModelIndex& index) const +{ + Qt::ItemFlags default_flags = QAbstractListModel::flags(index); + + if (index.isValid()) + return default_flags | Qt::ItemIsDragEnabled; + return default_flags; +} + +QStringList LayoutWidgetModel::mimeTypes() const +{ + QStringList types; + types << LAYOUT_WIDGET_MIME; + return types; +} + +QMimeData* LayoutWidgetModel::mimeData (const QModelIndexList& indexes ) const +{ + QMimeData *mimeData = new QMimeData(); + QByteArray encodedData; + + QDataStream stream(&encodedData, QIODevice::WriteOnly); + + foreach (const QModelIndex &index, indexes) { + if (index.isValid()) { + QString text = m_layout_widgets[index.row()]->getName(); + stream << text; + } + } + + mimeData->setData(LAYOUT_WIDGET_MIME, encodedData); + return mimeData; +} + +void LayoutWidgetModel::append(LayoutWidget* layout_widget) +{ + if (m_layout_widgets_dict.contains(layout_widget->getName())) + { + qWarning() << "Layout widget of this name already exists, can't add an other one: " << layout_widget->getName(); + delete layout_widget; + return; + } + beginInsertRows(QModelIndex(), m_layout_widgets.size(), m_layout_widgets.size()+1); + m_layout_widgets.append(layout_widget); + m_layout_widgets_dict.insert(layout_widget->getName(), layout_widget); + endInsertRows(); +} + + +const QList& LayoutWidgetModel::getLayoutWidgets() const +{ + return m_layout_widgets; +} + +const QHash& LayoutWidgetModel::getLayoutWidgetsDict() const +{ + return m_layout_widgets_dict; +} diff -r 017925589d4c -r c63d67895cbe layout_widget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/layout_widget.h Wed Aug 24 20:38:55 2011 +0200 @@ -0,0 +1,83 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#ifndef LAYOUT_WIDGETS_H +#define LAYOUT_WIDGETS_H + +#include + +#define LAYOUT_WIDGET_MIME "application/x-bellaciao-widget" + +typedef enum { + NONE, BOOL, LIST +} WidgetPropertyType; + +class WidgetProperty +{ + public: + WidgetProperty(const QString& name, const QString& tooltip); + + protected: + QString m_name, m_tooltip; + WidgetPropertyType m_type; + +}; + +class WidgetPropertyBool: public WidgetProperty +{ + public: + WidgetPropertyBool(const QString& name, bool checked=false, const QString& tooltip = QString()); + + protected: + bool m_checked; +}; + + + +class LayoutWidget +{ + public: + LayoutWidget(const QString &name, const QString& icon=""); + ~LayoutWidget(); + const QString& getName() const; + + private: + QString m_name, m_icon; + QList m_properties; +}; + +class LayoutWidgetModel: public QAbstractListModel +{ + Q_OBJECT + + public: + LayoutWidgetModel(QObject* parent=0); + ~LayoutWidgetModel(); + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags (const QModelIndex& index) const; + QStringList mimeTypes() const; + QMimeData* mimeData (const QModelIndexList& indexes ) const; + void append(LayoutWidget* layout_widget); + const QList& getLayoutWidgets() const; + const QHash& getLayoutWidgetsDict() const; + private: + QList m_layout_widgets; + QHash m_layout_widgets_dict; +}; +#endif diff -r 017925589d4c -r c63d67895cbe settings.cpp --- a/settings.cpp Sun Aug 14 18:03:54 2011 +0200 +++ b/settings.cpp Wed Aug 24 20:38:55 2011 +0200 @@ -18,6 +18,7 @@ #include "settings.h" #include "bellaciao.h" +#include "layout_designer.h" using namespace Qt; @@ -48,6 +49,15 @@ this->setAttribute(WA_DeleteOnClose); + //We add the settings in tabs + + // Contact list Layout + QVBoxLayout *layout = new QVBoxLayout; + LayoutDesigner* contact_list_layout = new LayoutDesigner; + layout->addWidget(contact_list_layout); + contactListLayoutTab->setLayout(layout); + + //We fill the profiles list m_bridge = Bridge::getBridge(); m_session = Session::getSession(); diff -r 017925589d4c -r c63d67895cbe settings.h --- a/settings.h Sun Aug 14 18:03:54 2011 +0200 +++ b/settings.h Wed Aug 24 20:38:55 2011 +0200 @@ -35,7 +35,7 @@ QString m_profile; }; -class Settings : public QWidget, private Ui::SettingsDlg +class Settings : public QWidget, private Ui::SettingsUI { Q_OBJECT diff -r 017925589d4c -r c63d67895cbe settings.ui --- a/settings.ui Sun Aug 14 18:03:54 2011 +0200 +++ b/settings.ui Wed Aug 24 20:38:55 2011 +0200 @@ -1,7 +1,7 @@ - SettingsDlg - + SettingsUI + 0 @@ -11,11 +11,11 @@ - Form + Bellaciao settings - + 0 @@ -33,7 +33,7 @@ - Check profiles you want to use + Tick profiles you want to use Qt::AlignCenter @@ -53,6 +53,9 @@ + + 0 + @@ -194,7 +197,7 @@ - + Contact list layout