D16484: [WIP] Add scratchpad plugin

Amish Naidu noreply at phabricator.kde.org
Thu Nov 1 09:44:20 GMT 2018


amhndu added a comment.


  Would something like this be worth adding ?
  
    cpp
    index 5c193432c9..1b5fb57352 100644
    --- a/plugins/scratchpad/scratchpadview.cpp
    +++ b/plugins/scratchpad/scratchpadview.cpp
    @@ -37,6 +37,7 @@
     #include <QWidgetAction>
     #include <QLineEdit>
     #include <QInputDialog>
    +#include <QPainter>
     
     // Use a delegate because the dataChanged signal doesn't tell us the previous name
     class FileRenameDelegate
    @@ -61,6 +62,31 @@ private:
         Scratchpad* m_scratchpad;
     };
     
    +// subclass to show a message when the list is empty
    +EmptyMessageListView::EmptyMessageListView(QWidget* parent)
    +    : QListView(parent)
    +{
    +}
    +
    +void EmptyMessageListView::paintEvent(QPaintEvent* event)
    +{
    +    if (model() && model()->rowCount(rootIndex()) > 0) {
    +        QListView::paintEvent(event);
    +    } else {
    +        QPainter painter(viewport());
    +        const auto margin =
    +            QMargins(parentWidget()->style()->pixelMetric(QStyle::PM_LayoutLeftMargin), 0,
    +                     parentWidget()->style()->pixelMetric(QStyle::PM_LayoutRightMargin), 0);
    +        painter.drawText(rect() - margin, Qt::AlignCenter | Qt::TextWordWrap, m_message);
    +    }
    +}
    +
    +void EmptyMessageListView::setEmptyMessage(const QString& message)
    +{
    +    m_message = message;
    +}
    +
    +
     ScratchpadView::ScratchpadView(QWidget* parent, Scratchpad* scratchpad)
         : QWidget(parent)
         , m_scratchpad(scratchpad)
    @@ -82,6 +108,7 @@ ScratchpadView::ScratchpadView(QWidget* parent, Scratchpad* scratchpad)
     
         scratchTree->setModel(modelProxy);
         scratchTree->setItemDelegate(new FileRenameDelegate(this, m_scratchpad));
    +    scratchTree->setEmptyMessage(i18n("Scratchpad lets you quickly run and experiment with code without a full project. Create a new scratch to start."));
     
         connect(scratchTree, &QListView::activated, this, &ScratchpadView::scratchActivated);
     
    diff --git a/plugins/scratchpad/scratchpadview.ui b/plugins/scratchpad/scratchpadview.ui
    index 31a144a8f7..5a19cffcfd 100644
    --- a/plugins/scratchpad/scratchpadview.ui
    +++ b/plugins/scratchpad/scratchpadview.ui
    @@ -28,7 +28,7 @@
         <number>0</number>
        </property>
        <item>
    -    <widget class="QListView" name="scratchTree"/>
    +    <widget class="EmptyMessageListView" name="scratchTree"/>
        </item>
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_2">
    @@ -39,6 +39,13 @@
        </item>
       </layout>
      </widget>
    + <customwidgets>
    +  <customwidget>
    +   <class>EmptyMessageListView</class>
    +   <extends>QListView</extends>
    +   <header>emptymessagelistview.h</header>
    +  </customwidget>
    + </customwidgets>
      <tabstops>
       <tabstop>scratchTree</tabstop>
      </tabstops>
  
  F6376866: image.png <https://phabricator.kde.org/F6376866>

REPOSITORY
  R32 KDevelop

REVISION DETAIL
  https://phabricator.kde.org/D16484

To: amhndu
Cc: brauch, kdevelop-devel, glebaccon, antismap, iodelay, vbspam, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20181101/588636d6/attachment-0001.html>


More information about the KDevelop-devel mailing list