added initial draft of FLUIQ (Flexible User-Interface with Qt) framework (integration patches will follow later)
git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1878 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
343
src/gui/fluiq/collapsible_widget.cpp
Normal file
343
src/gui/fluiq/collapsible_widget.cpp
Normal file
@@ -0,0 +1,343 @@
|
||||
/*
|
||||
* collapsible_widget.cpp - implementation of FLUIQ::CollapsibleWidget
|
||||
*
|
||||
* Copyright (c) 2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
* 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 2 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 (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QMouseEvent>
|
||||
#include <QtGui/QPainter>
|
||||
|
||||
#include "fluiq/collapsible_widget.h"
|
||||
|
||||
#include "embed.h"
|
||||
|
||||
|
||||
// implementation of FLUIQ::CollapsibleWidgetHeader
|
||||
|
||||
const int HEADER_MIN_HEIGHT = 20;
|
||||
|
||||
FLUIQ::CollapsibleWidgetHeader::CollapsibleWidgetHeader(
|
||||
CollapsibleWidget * _parent ) :
|
||||
Widget( _parent ),
|
||||
m_parent( _parent ),
|
||||
m_hovered( false ),
|
||||
m_pressed( false ),
|
||||
m_collapsed( false ),
|
||||
m_moved( false ),
|
||||
m_arrowCollapsed( embed::getIconPixmap( "fluiq/arrow-right" ) ),
|
||||
m_arrowExpanded( embed::getIconPixmap( "fluiq/arrow-down" ) )
|
||||
{
|
||||
QFont f = font();
|
||||
f.setBold( true );
|
||||
setFont( f );
|
||||
|
||||
setAttribute( Qt::WA_OpaquePaintEvent, true );
|
||||
|
||||
if( m_parent->orientation() == Qt::Horizontal )
|
||||
{
|
||||
setFixedWidth( HEADER_MIN_HEIGHT );
|
||||
}
|
||||
else
|
||||
{
|
||||
setFixedHeight( HEADER_MIN_HEIGHT );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FLUIQ::CollapsibleWidgetHeader::~CollapsibleWidgetHeader()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::CollapsibleWidgetHeader::setCollapsed( bool _c )
|
||||
{
|
||||
if( _c != m_collapsed )
|
||||
{
|
||||
m_collapsed = _c;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QSize FLUIQ::CollapsibleWidgetHeader::sizeHint( void ) const
|
||||
{
|
||||
if( m_parent->orientation() == Qt::Horizontal )
|
||||
{
|
||||
return QSize( HEADER_MIN_HEIGHT,
|
||||
HEADER_MIN_HEIGHT +
|
||||
fontMetrics().width( windowTitle() ) );
|
||||
}
|
||||
return QSize( HEADER_MIN_HEIGHT + fontMetrics().width( windowTitle() ),
|
||||
HEADER_MIN_HEIGHT );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::CollapsibleWidgetHeader::enterEvent( QEvent * _ev )
|
||||
{
|
||||
m_hovered = true;
|
||||
update();
|
||||
|
||||
Widget::enterEvent( _ev );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::CollapsibleWidgetHeader::leaveEvent( QEvent * _ev )
|
||||
{
|
||||
m_hovered = false;
|
||||
update();
|
||||
|
||||
Widget::leaveEvent( _ev );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::CollapsibleWidgetHeader::mousePressEvent( QMouseEvent * _ev )
|
||||
{
|
||||
if( _ev->button() == Qt::LeftButton )
|
||||
{
|
||||
QApplication::setOverrideCursor(
|
||||
m_parent->orientation() == Qt::Vertical ?
|
||||
Qt::SizeVerCursor : Qt::SizeHorCursor );
|
||||
m_pressed = true;
|
||||
m_moved = false;
|
||||
m_origMousePos = _ev->pos();
|
||||
update();
|
||||
_ev->accept();
|
||||
}
|
||||
else
|
||||
{
|
||||
Widget::mousePressEvent( _ev );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::CollapsibleWidgetHeader::mouseMoveEvent( QMouseEvent * _event )
|
||||
{
|
||||
if( m_pressed )
|
||||
{
|
||||
m_moved = true;
|
||||
|
||||
QSize ms = m_parent->minimumSize();
|
||||
|
||||
if( m_parent->orientation() == Qt::Vertical )
|
||||
{
|
||||
const int dy = _event->y() - m_origMousePos.y();
|
||||
ms.setHeight( qMax( 0, ms.height() + dy ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
const int dx = _event->x() - m_origMousePos.x();
|
||||
ms.setWidth( qMax( 0, ms.width() + dx ) );
|
||||
}
|
||||
m_parent->setMinimumSize( ms );
|
||||
m_origMousePos = _event->pos();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::CollapsibleWidgetHeader::mouseReleaseEvent( QMouseEvent * _ev )
|
||||
{
|
||||
if( _ev->button() == Qt::LeftButton && m_pressed )
|
||||
{
|
||||
QApplication::restoreOverrideCursor();
|
||||
m_pressed = false;
|
||||
update();
|
||||
_ev->accept();
|
||||
|
||||
if( m_moved == false )
|
||||
{
|
||||
if( m_collapsed )
|
||||
{
|
||||
m_collapsed = false;
|
||||
emit expanded();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_collapsed = true;
|
||||
emit collapsed();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Widget::mousePressEvent( _ev );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::CollapsibleWidgetHeader::paintEvent( QPaintEvent * _ev )
|
||||
{
|
||||
QPainter p( this );
|
||||
QRect r = rect();
|
||||
if( m_parent->orientation() == Qt::Horizontal )
|
||||
{
|
||||
r = QRect( 0, 0, height(), width() );
|
||||
p.rotate( -90 );
|
||||
p.translate( -height(), 0 );
|
||||
}
|
||||
|
||||
QLinearGradient grad( 0, 0, 0, r.height() );
|
||||
QColor c = palette().color( QPalette::Window );
|
||||
if( m_hovered )
|
||||
{
|
||||
c = c.lighter( 200 );
|
||||
}
|
||||
grad.setColorAt( 0, c.lighter( 280 ) );
|
||||
grad.setColorAt( 1, c );
|
||||
|
||||
p.fillRect( r, grad );
|
||||
|
||||
p.setPen( palette().color( QPalette::Text ) );
|
||||
p.drawPixmap( 8, 5, m_collapsed ? m_arrowCollapsed : m_arrowExpanded );
|
||||
p.drawText( 20, 10+r.height()-p.fontMetrics().height(), windowTitle() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// implementation of FLUIQ::CollapsibleWidget
|
||||
|
||||
|
||||
FLUIQ::CollapsibleWidget::CollapsibleWidget( Qt::Orientation _or,
|
||||
Widget * _parent ) :
|
||||
Widget( _parent ),
|
||||
m_orientation( _or ),
|
||||
m_masterLayout( NULL )
|
||||
{
|
||||
if( m_orientation == Qt::Horizontal )
|
||||
{
|
||||
m_masterLayout = new QHBoxLayout( this );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_masterLayout = new QVBoxLayout( this );
|
||||
}
|
||||
m_masterLayout->setMargin( 0 );
|
||||
m_masterLayout->setSpacing( 0 );
|
||||
|
||||
m_header = new CollapsibleWidgetHeader( this );
|
||||
|
||||
m_masterLayout->addWidget( m_header );
|
||||
|
||||
connect( m_header, SIGNAL( expanded() ),
|
||||
this, SLOT( expand() ) );
|
||||
connect( m_header, SIGNAL( collapsed() ),
|
||||
this, SLOT( collapse() ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FLUIQ::CollapsibleWidget::~CollapsibleWidget()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::CollapsibleWidget::addWidget( QWidget * _w )
|
||||
{
|
||||
m_masterLayout->addWidget( _w );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::CollapsibleWidget::insertWidget( int _idx, QWidget * _w )
|
||||
{
|
||||
m_masterLayout->insertWidget( _idx, _w );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::CollapsibleWidget::expand( void )
|
||||
{
|
||||
m_header->setCollapsed( false );
|
||||
|
||||
// set size properties
|
||||
setMaximumSize( QSize( 1 << 16, 1 << 16 ) );
|
||||
|
||||
// show all children
|
||||
foreach( QWidget * w, findChildren<QWidget *>() )
|
||||
{
|
||||
if( w != m_header && w->parentWidget() == this )
|
||||
{
|
||||
w->show();
|
||||
}
|
||||
}
|
||||
setMinimumSize( sizeHint() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FLUIQ::CollapsibleWidget::collapse( void )
|
||||
{
|
||||
m_header->setCollapsed( true );
|
||||
|
||||
// hide all children
|
||||
foreach( QWidget * w, findChildren<QWidget *>() )
|
||||
{
|
||||
if( w != m_header && w->parentWidget() == this )
|
||||
{
|
||||
w->hide();
|
||||
}
|
||||
}
|
||||
|
||||
// set size properties
|
||||
const QSize headerSize = m_header->sizeHint();
|
||||
if( m_orientation == Qt::Vertical )
|
||||
{
|
||||
setMaximumSize( QSize( 1 << 16, headerSize.height() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
setMaximumSize( QSize( headerSize.width(), 1 << 16 ) );
|
||||
}
|
||||
setMinimumSize( headerSize );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#include "fluiq/moc_collapsible_widget.cxx"
|
||||
|
||||
98
src/gui/fluiq/splitter.cpp
Normal file
98
src/gui/fluiq/splitter.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* splitter.cpp - implementation of FLUIQ::Splitter
|
||||
*
|
||||
* Copyright (c) 2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
* 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 2 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 (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QPaintEvent>
|
||||
|
||||
#include "fluiq/splitter.h"
|
||||
|
||||
|
||||
FLUIQ::Splitter::Splitter( Qt::Orientation _o, QWidget * _parent ) :
|
||||
QSplitter( _o, _parent )
|
||||
{
|
||||
setChildrenCollapsible( false );
|
||||
setSizePolicy( QSizePolicy::MinimumExpanding,
|
||||
QSizePolicy::MinimumExpanding );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FLUIQ::Splitter::~Splitter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QSplitterHandle * FLUIQ::Splitter::createHandle( void )
|
||||
{
|
||||
return new FLUIQ::SplitterHandle( orientation(), this );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
FLUIQ::SplitterHandle::SplitterHandle( Qt::Orientation _o,
|
||||
QSplitter * _parent ) :
|
||||
QSplitterHandle( _o, _parent )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FLUIQ::SplitterHandle::~SplitterHandle()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::SplitterHandle::paintEvent( QPaintEvent * _event )
|
||||
{
|
||||
QPainter painter( this );
|
||||
|
||||
QLinearGradient gradient;
|
||||
gradient.setColorAt( 0, QColor( 128, 128, 128 ) );
|
||||
gradient.setColorAt( 1, QColor( 32, 32, 32 ) );
|
||||
if( orientation() == Qt::Horizontal )
|
||||
{
|
||||
gradient.setStart( rect().left(), rect().height()/2 );
|
||||
gradient.setFinalStop( rect().right(), rect().height()/2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
gradient.setStart( rect().width()/2, rect().top() );
|
||||
gradient.setFinalStop( rect().width()/2, rect().bottom() );
|
||||
}
|
||||
painter.fillRect( _event->rect(), QBrush( gradient ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "fluiq/moc_splitter.cxx"
|
||||
|
||||
48
src/gui/fluiq/widget.cpp
Normal file
48
src/gui/fluiq/widget.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* widget.cpp - implementation of FLUIQ::Widget
|
||||
*
|
||||
* Copyright (c) 2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
* 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 2 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 (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "fluiq/widget.h"
|
||||
|
||||
|
||||
FLUIQ::Widget::Widget( QWidget * _parent ) :
|
||||
QWidget( _parent )
|
||||
{
|
||||
QPalette pal = palette();
|
||||
pal.setColor( QPalette::Window, QColor( 21, 21, 21 ) );
|
||||
pal.setColor( QPalette::Text, QColor( 255, 255, 255 ) );
|
||||
setPalette( pal );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FLUIQ::Widget::~Widget()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "fluiq/moc_widget.cxx"
|
||||
|
||||
73
src/gui/fluiq/widget_container.cpp
Normal file
73
src/gui/fluiq/widget_container.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* widget_container.cpp - implementation of FLUIQ::WidgetContainer
|
||||
*
|
||||
* Copyright (c) 2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
* 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 2 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 (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QScrollArea>
|
||||
|
||||
#include "fluiq/widget_container.h"
|
||||
#include "fluiq/splitter.h"
|
||||
|
||||
|
||||
|
||||
FLUIQ::WidgetContainer::WidgetContainer( Qt::Orientation _o,
|
||||
Widget * _parent ) :
|
||||
Widget( _parent ),
|
||||
m_orientation( _o ),
|
||||
m_scrollArea( NULL ),
|
||||
m_splitter( NULL )
|
||||
{
|
||||
QVBoxLayout * myLayout = new QVBoxLayout( this );
|
||||
myLayout->setSpacing( 0 );
|
||||
myLayout->setMargin( 0 );
|
||||
|
||||
m_scrollArea = new QScrollArea( this );
|
||||
m_scrollArea->setWidgetResizable( true );
|
||||
m_scrollArea->setFrameStyle( QFrame::NoFrame );
|
||||
|
||||
myLayout->addWidget( m_scrollArea );
|
||||
|
||||
m_splitter = new Splitter( m_orientation );
|
||||
m_scrollArea->setWidget( m_splitter );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FLUIQ::WidgetContainer::~WidgetContainer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::WidgetContainer::addWidget( QWidget * _widget )
|
||||
{
|
||||
m_splitter->addWidget( _widget );
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "fluiq/moc_widget_container.cxx"
|
||||
|
||||
73
src/gui/fluiq/workspace.cpp
Normal file
73
src/gui/fluiq/workspace.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* workspace.cpp - implementation of FLUIQ::Workspace
|
||||
*
|
||||
* Copyright (c) 2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
* 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 2 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 (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <QtGui/QBoxLayout>
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
#include "fluiq/workspace.h"
|
||||
|
||||
|
||||
FLUIQ::Workspace::Workspace( QWidget * _parent ) :
|
||||
Widget( _parent ),
|
||||
m_masterLayout( new QVBoxLayout( this ) )
|
||||
{
|
||||
m_masterLayout->setMargin( 0 );
|
||||
m_masterLayout->setSpacing( 0 );
|
||||
|
||||
m_currentSplitter = new Splitter( Qt::Horizontal, this );
|
||||
m_masterLayout->addWidget( m_currentSplitter );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FLUIQ::Workspace::~Workspace()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::Workspace::addWidget( QWidget * _w )
|
||||
{
|
||||
m_currentSplitter = new Splitter( Qt::Horizontal, this );
|
||||
m_masterLayout->addWidget( m_currentSplitter );
|
||||
|
||||
m_currentSplitter->addWidget( _w );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLUIQ::Workspace::addWidgetToExistingRow( QWidget * _w )
|
||||
{
|
||||
m_currentSplitter->addWidget( _w );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#include "fluiq/moc_workspace.cxx"
|
||||
|
||||
Reference in New Issue
Block a user