Skip to content

Commit

Permalink
Improve filter menu size and placement
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatherly committed Oct 25, 2014
1 parent f7fad66 commit 8776bf8
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/docks/filtersdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ FiltersDock::FiltersDock(MetadataModel* metadataModel, AttachedFiltersModel* att
modulePath.cd("modules");
m_qview.engine()->addImportPath(modulePath.path());

QmlUtilities::setCommonProperties(m_qview.rootContext());
QmlUtilities::setCommonProperties(&m_qview);
m_qview.rootContext()->setContextProperty("metadatamodel", metadataModel);
m_qview.rootContext()->setContextProperty("attachedfiltersmodel", attachedModel);
setCurrentFilter(NULL, NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/docks/timelinedock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ TimelineDock::TimelineDock(QWidget *parent) :
importPath.cd("modules");
m_quickView.engine()->addImportPath(importPath.path());
m_quickView.engine()->addImageProvider(QString("thumbnail"), new ThumbnailProvider);
QmlUtilities::setCommonProperties(m_quickView.rootContext());
QmlUtilities::setCommonProperties(&m_quickView);
m_quickView.rootContext()->setContextProperty("timeline", this);
m_quickView.rootContext()->setContextProperty("multitrack", &m_model);
m_quickView.setResizeMode(QQuickView::SizeRootObjectToView);
Expand Down
2 changes: 1 addition & 1 deletion src/glwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ GLWidget::GLWidget(QObject *parent)
QDir importPath = QmlUtilities::qmlDir();
importPath.cd("modules");
engine()->addImportPath(importPath.path());
QmlUtilities::setCommonProperties(rootContext());
QmlUtilities::setCommonProperties((QQuickView*)this);
rootContext()->setContextProperty("video", this);
setSource(QmlUtilities::blankVui());

Expand Down
2 changes: 1 addition & 1 deletion src/models/metadatamodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void MetadataModel::add(QmlMetadata* data)
data->setParent(this);
}

QmlMetadata* MetadataModel::get(int index)
QmlMetadata* MetadataModel::get(int index) const
{
if( index < m_list.size() ) {
return m_list[index];
Expand Down
4 changes: 2 additions & 2 deletions src/models/metadatamodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class MetadataModel : public QAbstractListModel
explicit MetadataModel(QObject *parent = 0);

// Implement QAbstractListModel
int rowCount(const QModelIndex &parent = QModelIndex()) const;
Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
QHash<int, QByteArray> roleNames() const;
Qt::ItemFlags flags(const QModelIndex &index) const;

// Direct access to QmlMetadata
void add(QmlMetadata* data);
QmlMetadata* get(int index);
Q_INVOKABLE QmlMetadata* get(int index) const;

private:
typedef QList<QmlMetadata*> MetadataList;
Expand Down
57 changes: 47 additions & 10 deletions src/qml/views/filter/FilterMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,55 @@ import QtQuick.Controls.Styles 1.1
Window {
id: filterWindow

property bool showAll: false
property bool _showAll: false
property int _itemHeight: 30

signal filterSelected(int index)

function popup() {
var cursorPoint = application.mousePos
filterWindow.x = cursorPoint.x
filterWindow.y = cursorPoint.y - menuListView.height / 2
function popup(triggerItem) {
var menuRect = _menuRect(triggerItem)
filterWindow.x = menuRect.x
filterWindow.y = menuRect.y
filterWindow.height = menuRect.height
filterWindow.visible = true
filterWindow.requestActivate()
menuListView.currentIndex = -1
}

function _menuRect(triggerItem) {
var result = Qt.rect(0, 0, 0, 0)
var itemPos = triggerItem.mapToItem(null,0,0)
var triggerPos = Qt.point(itemPos.x + view.pos.x, itemPos.y + view.pos.y)
var mainWinRect = application.mainWinRect

// Calculate the max possible height of the menu
var i = 0
var visibleItems = 0;
for( i = 0; i < metadatamodel.rowCount(); i++ ) {
var meta = metadatamodel.get(i)
if( !meta.isHidden && (meta.isFavorite || _showAll) ) {
visibleItems++
}
}
var maxHeight = (visibleItems * _itemHeight) + padRect.height + moreButton.height
result.height = Math.min(maxHeight, mainWinRect.height)

// Calculate the y position
result.y = triggerPos.y - result.height / 2 // Ideal position is centered
if( result.y < mainWinRect.y ) {
// Window would be higher than the application window. Move it down
result.y = mainWinRect.y
} else if( result.y + result.height > mainWinRect.y + mainWinRect.height ) {
// Window would be lower than the application window. Move it up
result.y = mainWinRect.y + mainWinRect.height - result.height
}

// Calculate the x position
result.x = triggerPos.x

return result
}

color: activePalette.window
flags: Qt.ToolTip
width: 200
Expand All @@ -53,12 +89,12 @@ Window {
id: filterMenuDelegate

Item {
visible: !hidden && (favorite || showAll)
height: visible ? filterItemRow.height : 0
visible: !hidden && (favorite || _showAll)
height: visible ? _itemHeight : 0

Row {
id: filterItemRow
height: 30
height: _itemHeight

Button {
id: favButton
Expand Down Expand Up @@ -135,6 +171,7 @@ Window {
}

Rectangle {
id: padRect
color: activePalette.base
height: 2
width: parent.width
Expand All @@ -145,8 +182,8 @@ Window {
width: parent.width
text: qsTr('More')
onClicked: {
showAll = !showAll
if (showAll) {
_showAll = !_showAll
if (_showAll) {
text = qsTr('Less')
} else {
text = qsTr('More')
Expand Down
2 changes: 1 addition & 1 deletion src/qml/views/filter/filterview.qml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Rectangle {
Layout.fillWidth: true
iconName: 'list-add'
tooltip: qsTr('Add a Filter')
onClicked: filterMenu.popup()
onClicked: filterMenu.popup(addButton)
}
Button {
id: removeButton
Expand Down
9 changes: 2 additions & 7 deletions src/qmltypes/qmlapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,7 @@ QString QmlApplication::numericLocale()
#endif
}

QPoint QmlApplication::mainWinPos()
QRect QmlApplication::mainWinRect()
{
return MAIN.pos();
}

QSize QmlApplication::mainWinSize()
{
return MAIN.size();
return MAIN.geometry();
}
9 changes: 4 additions & 5 deletions src/qmltypes/qmlapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <QDir>
#include <QPoint>
#include <QColor>
#include <QSize>
#include <QRect>

class QmlApplication : public QObject
{
Expand All @@ -35,8 +35,8 @@ class QmlApplication : public QObject
Q_PROPERTY(QColor toolTipTextColor READ toolTipTextColor NOTIFY paletteChanged)
Q_PROPERTY(QString OS READ OS CONSTANT)
Q_PROPERTY(QString numericLocale READ numericLocale CONSTANT)
Q_PROPERTY(QPoint mainWinPos READ mainWinPos);
Q_PROPERTY(QSize mainWinSize READ mainWinSize);
Q_PROPERTY(QRect mainWinRect READ mainWinRect);


public:
static QmlApplication& singleton();
Expand All @@ -46,8 +46,7 @@ class QmlApplication : public QObject
static QColor toolTipTextColor();
static QString OS();
static QString numericLocale();
static QPoint mainWinPos();
static QSize mainWinSize();
static QRect mainWinRect();

signals:
void paletteChanged();
Expand Down
6 changes: 5 additions & 1 deletion src/qmltypes/qmlutilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "qmltypes/colorwheelitem.h"
#include "qmltypes/qmlprofile.h"
#include "qmltypes/qmlutilities.h"
#include "qmltypes/qmlview.h"
#include "qmltypes/qmlfile.h"
#include "qmltypes/qmlhtmleditor.h"
#include "qmltypes/qmlmetadata.h"
Expand All @@ -30,6 +31,7 @@
#include <QCursor>
#include <QtQml>
#include <QQmlContext>
#include <QQuickView>

QmlUtilities::QmlUtilities(QObject *parent) :
QObject(parent)
Expand All @@ -46,11 +48,13 @@ void QmlUtilities::registerCommonTypes()
qmlRegisterType<ColorWheelItem>("Shotcut.Controls", 1, 0, "ColorWheelItem");
}

void QmlUtilities::setCommonProperties(QQmlContext* rootContext)
void QmlUtilities::setCommonProperties(QQuickView* qview)
{
QQmlContext* rootContext = qview->rootContext();
rootContext->setContextProperty("settings", &ShotcutSettings::singleton());
rootContext->setContextProperty("application", &QmlApplication::singleton());
rootContext->setContextProperty("profile", &QmlProfile::singleton());
rootContext->setContextProperty("view", new QmlView(qview));
}

QDir QmlUtilities::qmlDir()
Expand Down
4 changes: 2 additions & 2 deletions src/qmltypes/qmlutilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <QPoint>
#include <QUrl>

class QQmlContext;
class QQuickView;

class QmlUtilities : public QObject
{
Expand All @@ -34,7 +34,7 @@ class QmlUtilities : public QObject
explicit QmlUtilities(QObject *parent = 0);

static void registerCommonTypes();
static void setCommonProperties(QQmlContext* rootContext);
static void setCommonProperties(QQuickView* qview);
static QDir qmlDir();
static QUrl blankVui();
};
Expand Down
32 changes: 32 additions & 0 deletions src/qmltypes/qmlview.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2014 Meltytech, LLC
* Author: Brian Matherly <code@brianmatherly.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "qmlview.h"
#include <QQuickView>
#include <QDebug>

QmlView::QmlView(QQuickView* qview)
: QObject(qview)
, m_qview(qview)
{
}

QPoint QmlView::pos()
{
return m_qview->mapToGlobal(QPoint(0,0));
}
40 changes: 40 additions & 0 deletions src/qmltypes/qmlview.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2014 Meltytech, LLC
* Author: Brian Matherly <code@brianmatherly.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef QMLVIEW_H
#define QMLVIEW_H

#include <QObject>
#include <QPoint>

class QQuickView;

class QmlView : public QObject
{
Q_OBJECT
Q_PROPERTY(QPoint pos READ pos);

public:
explicit QmlView(QQuickView* qview);
QPoint pos();

private:
QQuickView* m_qview;
};

#endif // QMLVIEW_H
2 changes: 2 additions & 0 deletions src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ SOURCES += main.cpp\
models/multitrackmodel.cpp \
docks/timelinedock.cpp \
qmltypes/qmlutilities.cpp \
qmltypes/qmlview.cpp \
qmltypes/thumbnailprovider.cpp \
commands/timelinecommands.cpp \
util.cpp \
Expand Down Expand Up @@ -152,6 +153,7 @@ HEADERS += mainwindow.h \
models/multitrackmodel.h \
docks/timelinedock.h \
qmltypes/qmlutilities.h \
qmltypes/qmlview.h \
qmltypes/thumbnailprovider.h \
commands/timelinecommands.h \
util.h \
Expand Down

0 comments on commit 8776bf8

Please sign in to comment.