toolbar reimplemented

This commit is contained in:
itsmattkc
2019-06-21 13:10:55 -07:00
parent 8d66f11d6d
commit 839082895b
17 changed files with 579 additions and 7 deletions
+1
View File
@@ -16,6 +16,7 @@
add_subdirectory(project)
add_subdirectory(timeline)
add_subdirectory(tool)
add_subdirectory(viewer)
set(OLIVE_SOURCES
+1 -1
View File
@@ -23,4 +23,4 @@ private:
ProjectExplorer* explorer_;
};
#endif // PROJECT_H
#endif // PROJECT_PANEL_H
+3 -3
View File
@@ -1,5 +1,5 @@
#ifndef TIMELINE_H
#define TIMELINE_H
#ifndef TIMELINE_PANEL_H
#define TIMELINE_PANEL_H
#include "widget/panel/panel.h"
@@ -16,4 +16,4 @@ private:
void Retranslate();
};
#endif // TIMELINE_H
#endif // TIMELINE_PANEL_H
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# 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/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
panel/tool/tool.h
panel/tool/tool.cpp
PARENT_SCOPE
)
+26
View File
@@ -0,0 +1,26 @@
#include "tool.h"
#include "widget/toolbar/toolbar.h"
ToolPanel::ToolPanel(QWidget *parent) :
PanelWidget(parent)
{
Toolbar* t = new Toolbar(this);
setWidget(t);
Retranslate();
}
void ToolPanel::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
Retranslate();
}
QDockWidget::changeEvent(e);
}
void ToolPanel::Retranslate()
{
SetTitle(tr("Tools"));
}
+19
View File
@@ -0,0 +1,19 @@
#ifndef TOOL_PANEL_H
#define TOOL_PANEL_H
#include "widget/panel/panel.h"
class ToolPanel : public PanelWidget
{
Q_OBJECT
public:
ToolPanel(QWidget* parent);
protected:
virtual void changeEvent(QEvent* e) override;
private:
void Retranslate();
};
#endif // TOOL_PANEL_H
-3
View File
@@ -5,9 +5,6 @@
ViewerPanel::ViewerPanel(QWidget *parent) :
PanelWidget(parent)
{
SetTitle(tr("Viewer"));
SetSubtitle(tr("(None)"));
// QObject system handles deleting this
ViewerWidget* viewer = new ViewerWidget(this);
+28
View File
@@ -26,6 +26,19 @@ QIcon olive::icon::Redo;
QIcon olive::icon::TreeView;
QIcon olive::icon::ListView;
QIcon olive::icon::IconView;
QIcon olive::icon::ToolPointer;
QIcon olive::icon::ToolEdit;
QIcon olive::icon::ToolRipple;
QIcon olive::icon::ToolRazor;
QIcon olive::icon::ToolSlip;
QIcon olive::icon::ToolSlide;
QIcon olive::icon::ToolHand;
QIcon olive::icon::ToolTransition;
QIcon olive::icon::Snapping;
QIcon olive::icon::ZoomIn;
QIcon olive::icon::ZoomOut;
QIcon olive::icon::Record;
QIcon olive::icon::Add;
void olive::icon::LoadAll()
{
@@ -44,6 +57,21 @@ void olive::icon::LoadAll()
TreeView = Create("treeview");
ListView = Create("listview");
IconView = Create("iconview");
ToolPointer = Create("arrow");
ToolEdit = Create("beam");
ToolRipple = Create("ripple");
ToolRazor = Create("razor");
ToolSlip = Create("slip");
ToolSlide = Create("slide");
ToolHand = Create("hand");
ToolTransition = Create("transition-tool");
Snapping = Create("magnet");
ZoomIn = Create("zoomin");
ZoomOut = Create("zoomout");
Record = Create("record");
Add = Create("add-button");
}
QIcon olive::icon::Create(const QString &name)
+17
View File
@@ -24,6 +24,23 @@ extern QIcon TreeView;
extern QIcon ListView;
extern QIcon IconView;
// Tool Icons
extern QIcon ToolPointer;
extern QIcon ToolEdit;
extern QIcon ToolRipple;
extern QIcon ToolRazor;
extern QIcon ToolSlip;
extern QIcon ToolSlide;
extern QIcon ToolHand;
extern QIcon ToolTransition;
// Miscellaneous Icons
extern QIcon Snapping;
extern QIcon ZoomIn;
extern QIcon ZoomOut;
extern QIcon Record;
extern QIcon Add;
QIcon Create(const QString& name);
void LoadAll();
+2
View File
@@ -14,11 +14,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
add_subdirectory(flowlayout)
add_subdirectory(menu)
add_subdirectory(panel)
add_subdirectory(playbackcontrols)
add_subdirectory(projectexplorer)
add_subdirectory(projecttoolbar)
add_subdirectory(toolbar)
add_subdirectory(viewer)
set(OLIVE_SOURCES
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# 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/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
widget/flowlayout/flowlayout.h
widget/flowlayout/flowlayout.cpp
PARENT_SCOPE
)
+200
View File
@@ -0,0 +1,200 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtWidgets>
#include "flowlayout.h"
FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
: QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
{
setContentsMargins(margin, margin, margin, margin);
}
FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing)
: m_hSpace(hSpacing), m_vSpace(vSpacing)
{
setContentsMargins(margin, margin, margin, margin);
}
FlowLayout::~FlowLayout()
{
QLayoutItem *item;
while ((item = takeAt(0)))
delete item;
}
void FlowLayout::addItem(QLayoutItem *item)
{
itemList.append(item);
}
int FlowLayout::horizontalSpacing() const
{
if (m_hSpace >= 0) {
return m_hSpace;
} else {
return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
}
}
int FlowLayout::verticalSpacing() const
{
if (m_vSpace >= 0) {
return m_vSpace;
} else {
return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
}
}
int FlowLayout::count() const
{
return itemList.size();
}
QLayoutItem *FlowLayout::itemAt(int index) const
{
return itemList.value(index);
}
QLayoutItem *FlowLayout::takeAt(int index)
{
if (index >= 0 && index < itemList.size())
return itemList.takeAt(index);
else
return 0;
}
Qt::Orientations FlowLayout::expandingDirections() const
{
return 0;
}
bool FlowLayout::hasHeightForWidth() const
{
return true;
}
int FlowLayout::heightForWidth(int width) const
{
int height = doLayout(QRect(0, 0, width, 0), true);
return height;
}
void FlowLayout::setGeometry(const QRect &rect)
{
QLayout::setGeometry(rect);
doLayout(rect, false);
}
QSize FlowLayout::sizeHint() const
{
return minimumSize();
}
QSize FlowLayout::minimumSize() const
{
QSize size;
QLayoutItem *item;
foreach (item, itemList)
size = size.expandedTo(item->minimumSize());
size += QSize(2*margin(), 2*margin());
return size;
}
int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
{
int left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
int x = effectiveRect.x();
int y = effectiveRect.y();
int lineHeight = 0;
QLayoutItem *item;
foreach (item, itemList) {
QWidget *wid = item->widget();
int spaceX = horizontalSpacing();
if (spaceX == -1)
spaceX = wid->style()->layoutSpacing(
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
int spaceY = verticalSpacing();
if (spaceY == -1)
spaceY = wid->style()->layoutSpacing(
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
int nextX = x + item->sizeHint().width() + spaceX;
if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
x = effectiveRect.x();
y = y + lineHeight + spaceY;
nextX = x + item->sizeHint().width() + spaceX;
lineHeight = 0;
}
if (!testOnly)
item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
x = nextX;
lineHeight = qMax(lineHeight, item->sizeHint().height());
}
return y + lineHeight - rect.y() + bottom;
}
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
{
QObject *parent = this->parent();
if (!parent) {
return -1;
} else if (parent->isWidgetType()) {
QWidget *pw = static_cast<QWidget *>(parent);
return pw->style()->pixelMetric(pm, 0, pw);
} else {
return static_cast<QLayout *>(parent)->spacing();
}
}
+87
View File
@@ -0,0 +1,87 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef FLOWLAYOUT_H
#define FLOWLAYOUT_H
#include <QLayout>
#include <QRect>
#include <QStyle>
class FlowLayout : public QLayout
{
public:
explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
~FlowLayout();
void addItem(QLayoutItem *item) override;
int horizontalSpacing() const;
int verticalSpacing() const;
Qt::Orientations expandingDirections() const override;
bool hasHeightForWidth() const override;
int heightForWidth(int) const override;
int count() const override;
QLayoutItem *itemAt(int index) const override;
QSize minimumSize() const override;
void setGeometry(const QRect &rect) override;
QSize sizeHint() const override;
QLayoutItem *takeAt(int index) override;
private:
int doLayout(const QRect &rect, bool testOnly) const;
int smartSpacing(QStyle::PixelMetric pm) const;
QList<QLayoutItem *> itemList;
int m_hSpace;
int m_vSpace;
};
#endif // FLOWLAYOUT_H
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# 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/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
widget/toolbar/toolbar.h
widget/toolbar/toolbar.cpp
PARENT_SCOPE
)
+93
View File
@@ -0,0 +1,93 @@
#include "toolbar.h"
#include <QPushButton>
#include <QEvent>
#include "widget/flowlayout/flowlayout.h"
#include "ui/icons/icons.h"
Toolbar::Toolbar(QWidget *parent) :
QWidget(parent)
{
FlowLayout* layout = new FlowLayout(this);
layout->setMargin(0);
btn_pointer_tool = new QPushButton();
btn_pointer_tool->setIcon(olive::icon::ToolPointer);
layout->addWidget(btn_pointer_tool);
btn_edit_tool = new QPushButton();
btn_edit_tool->setIcon(olive::icon::ToolEdit);
layout->addWidget(btn_edit_tool);
btn_ripple_tool = new QPushButton();
btn_ripple_tool->setIcon(olive::icon::ToolRipple);
layout->addWidget(btn_ripple_tool);
btn_razor_tool = new QPushButton();
btn_razor_tool->setIcon(olive::icon::ToolRazor);
layout->addWidget(btn_razor_tool);
btn_slip_tool = new QPushButton();
btn_slip_tool->setIcon(olive::icon::ToolSlip);
layout->addWidget(btn_slip_tool);
btn_slide_tool = new QPushButton();
btn_slide_tool->setIcon(olive::icon::ToolSlide);
layout->addWidget(btn_slide_tool);
btn_hand_tool = new QPushButton();
btn_hand_tool->setIcon(olive::icon::ToolHand);
layout->addWidget(btn_hand_tool);
btn_transition_tool = new QPushButton();
btn_transition_tool->setIcon(olive::icon::ToolTransition);
layout->addWidget(btn_transition_tool);
btn_snapping_toggle = new QPushButton();
btn_snapping_toggle->setIcon(olive::icon::Snapping);
layout->addWidget(btn_snapping_toggle);
btn_zoom_in = new QPushButton();
btn_zoom_in->setIcon(olive::icon::ZoomIn);
layout->addWidget(btn_zoom_in);
btn_zoom_out = new QPushButton();
btn_zoom_out->setIcon(olive::icon::ZoomOut);
layout->addWidget(btn_zoom_out);
btn_record = new QPushButton();
btn_record->setIcon(olive::icon::Record);
layout->addWidget(btn_record);
btn_add = new QPushButton();
btn_add->setIcon(olive::icon::Add);
layout->addWidget(btn_add);
Retranslate();
}
void Toolbar::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
Retranslate();
}
QWidget::changeEvent(e);
}
void Toolbar::Retranslate()
{
btn_pointer_tool->setToolTip(tr("Pointer Tool"));
btn_edit_tool->setToolTip(tr("Edit Tool"));
btn_ripple_tool->setToolTip(tr("Ripple Tool"));
btn_razor_tool->setToolTip(tr("Razor Tool"));
btn_slip_tool->setToolTip(tr("Slip Tool"));
btn_slide_tool->setToolTip(tr("Slide Tool"));
btn_hand_tool->setToolTip(tr("Hand Tool"));
btn_transition_tool->setToolTip(tr("Transition Tool"));
btn_snapping_toggle->setToolTip(tr("Toggle Snapping"));
btn_zoom_in->setToolTip(tr("Zoom In"));
btn_zoom_out->setToolTip(tr("Zoom Out"));
btn_record->setToolTip(tr("Record Audio"));
btn_add->setToolTip(tr("Add Object"));
}
+32
View File
@@ -0,0 +1,32 @@
#ifndef TOOLBAR_H
#define TOOLBAR_H
#include <QPushButton>
class Toolbar : public QWidget
{
public:
Toolbar(QWidget* parent);
protected:
virtual void changeEvent(QEvent* e) override;
private:
void Retranslate();
QPushButton* btn_pointer_tool;
QPushButton* btn_edit_tool;
QPushButton* btn_ripple_tool;
QPushButton* btn_razor_tool;
QPushButton* btn_slip_tool;
QPushButton* btn_slide_tool;
QPushButton* btn_hand_tool;
QPushButton* btn_transition_tool;
QPushButton* btn_snapping_toggle;
QPushButton* btn_zoom_in;
QPushButton* btn_zoom_out;
QPushButton* btn_record;
QPushButton* btn_add;
};
#endif // TOOLBAR_H
+4
View File
@@ -24,6 +24,7 @@
#include "panel/project/project.h"
#include "panel/viewer/viewer.h"
#include "panel/timeline/timeline.h"
#include "panel/tool/tool.h"
// Main menu bar
#include "mainmenu.h"
@@ -61,6 +62,9 @@ void olive::MainWindow::ProjectOpen(Project* p)
ViewerPanel* viewer_panel2 = new ViewerPanel(this);
addDockWidget(Qt::TopDockWidgetArea, viewer_panel2);
ToolPanel* tool_panel = new ToolPanel(this);
addDockWidget(Qt::BottomDockWidgetArea, tool_panel);
TimelinePanel* timeline_panel = new TimelinePanel(this);
addDockWidget(Qt::BottomDockWidgetArea, timeline_panel);
}