Added automatic layout mode to the desktop grid effect. Patch based off one by Christian Mollekopf.
BUG: 157196 svn path=/trunk/KDE/kdebase/workspace/; revision=857049
This commit is contained in:
parent
e992879263
commit
269242303f
5 changed files with 63 additions and 18 deletions
|
@ -71,7 +71,7 @@ DesktopGridEffect::DesktopGridEffect()
|
|||
|
||||
border = conf.readEntry( "BorderWidth", 10 );
|
||||
desktopNameAlignment = Qt::Alignment( conf.readEntry( "DesktopNameAlignment", 0 ));
|
||||
customLayout = conf.readEntry( "CustomLayout", 0 ) ? true : false;
|
||||
layoutMode = conf.readEntry( "LayoutMode", int( LayoutPager ));
|
||||
customLayoutRows = conf.readEntry( "CustomLayoutRows", 2 );
|
||||
}
|
||||
|
||||
|
@ -602,11 +602,28 @@ void DesktopGridEffect::setup()
|
|||
hoverTimeline[effects->currentDesktop() - 1].setProgress( 1.0 );
|
||||
|
||||
// We need these variables for every paint so lets cache them
|
||||
effects->calcDesktopLayout( &gridSize.rwidth(), &gridSize.rheight(), &orientation );
|
||||
if( customLayout )
|
||||
int x, y;
|
||||
int numDesktops = effects->numberOfDesktops();
|
||||
switch( layoutMode )
|
||||
{
|
||||
gridSize.setWidth( ceil( effects->numberOfDesktops() / double( customLayoutRows )));
|
||||
gridSize.setHeight( customLayoutRows );
|
||||
default:
|
||||
case LayoutPager:
|
||||
effects->calcDesktopLayout( &gridSize.rwidth(), &gridSize.rheight(), &orientation );
|
||||
break;
|
||||
case LayoutAutomatic:
|
||||
y = sqrt( numDesktops ) + 0.5;
|
||||
x = float( numDesktops ) / float( y ) + 0.5;
|
||||
if( x * y < numDesktops )
|
||||
x++;
|
||||
orientation = Qt::Horizontal;
|
||||
gridSize.setWidth( x );
|
||||
gridSize.setHeight( y );
|
||||
break;
|
||||
case LayoutCustom:
|
||||
effects->calcDesktopLayout( &gridSize.rwidth(), &gridSize.rheight(), &orientation );
|
||||
gridSize.setWidth( ceil( effects->numberOfDesktops() / double( customLayoutRows )));
|
||||
gridSize.setHeight( customLayoutRows );
|
||||
break;
|
||||
}
|
||||
setCurrentDesktop( effects->currentDesktop() );
|
||||
scale.clear();
|
||||
|
|
|
@ -44,8 +44,12 @@ class DesktopGridEffect
|
|||
virtual void windowInputMouseEvent( Window w, QEvent* e );
|
||||
virtual void grabbedKeyboardEvent( QKeyEvent* e );
|
||||
virtual bool borderActivated( ElectricBorder border );
|
||||
|
||||
enum { LayoutPager, LayoutAutomatic, LayoutCustom }; // Layout modes
|
||||
|
||||
private slots:
|
||||
void toggle();
|
||||
|
||||
private:
|
||||
QPointF scalePos( const QPoint& pos, int desktop, int screen = -1 ) const;
|
||||
QPoint unscalePos( const QPoint& pos, int* desktop = NULL ) const;
|
||||
|
@ -61,7 +65,7 @@ class DesktopGridEffect
|
|||
int zoomDuration;
|
||||
int border;
|
||||
Qt::Alignment desktopNameAlignment;
|
||||
bool customLayout;
|
||||
int layoutMode;
|
||||
int customLayoutRows;
|
||||
|
||||
bool activated;
|
||||
|
|
|
@ -95,8 +95,8 @@ DesktopGridEffectConfig::DesktopGridEffectConfig(QWidget* parent, const QVariant
|
|||
connect( m_ui->zoomDurationSpin, SIGNAL( valueChanged( int )), this, SLOT( changed() ));
|
||||
connect( m_ui->borderWidthSpin, SIGNAL( valueChanged( int )), this, SLOT( changed() ));
|
||||
connect( m_ui->desktopNameAlignmentCombo, SIGNAL( currentIndexChanged( int )), this, SLOT( changed() ));
|
||||
connect( m_ui->layoutBox, SIGNAL( stateChanged( int )), this, SLOT( changed() ));
|
||||
connect( m_ui->layoutBox, SIGNAL( stateChanged( int )), this, SLOT( layoutSelectionChanged() ));
|
||||
connect( m_ui->layoutCombo, SIGNAL( currentIndexChanged( int )), this, SLOT( changed() ));
|
||||
connect( m_ui->layoutCombo, SIGNAL( currentIndexChanged( int )), this, SLOT( layoutSelectionChanged() ));
|
||||
connect( m_ui->layoutRowsSpin, SIGNAL( valueChanged( int )), this, SLOT( changed() ));
|
||||
connect( m_ui->shortcutEditor, SIGNAL( keyChange() ), this, SLOT( changed() ));
|
||||
|
||||
|
@ -126,10 +126,8 @@ void DesktopGridEffectConfig::load()
|
|||
Qt::Alignment alignment = Qt::Alignment( conf.readEntry( "DesktopNameAlignment", 0 ));
|
||||
m_ui->desktopNameAlignmentCombo->setCurrentIndex( m_alignmentItems.indexOf( alignment ));
|
||||
|
||||
if( conf.readEntry( "CustomLayout", false ))
|
||||
m_ui->layoutBox->setCheckState( Qt::Checked );
|
||||
else
|
||||
m_ui->layoutBox->setCheckState( Qt::Unchecked );
|
||||
int layoutMode = conf.readEntry( "LayoutMode", int( DesktopGridEffect::LayoutPager ));
|
||||
m_ui->layoutCombo->setCurrentIndex( layoutMode );
|
||||
layoutSelectionChanged();
|
||||
|
||||
m_ui->layoutRowsSpin->setValue( conf.readEntry( "CustomLayoutRows", 2 ));
|
||||
|
@ -155,7 +153,9 @@ void DesktopGridEffectConfig::save()
|
|||
alignment = int( m_alignmentItems[alignment] );
|
||||
conf.writeEntry( "DesktopNameAlignment", alignment );
|
||||
|
||||
conf.writeEntry( "CustomLayout", m_ui->layoutBox->checkState() == Qt::Checked ? 1 : 0 );
|
||||
int layoutMode = m_ui->layoutCombo->currentIndex();
|
||||
conf.writeEntry( "LayoutMode", layoutMode );
|
||||
|
||||
conf.writeEntry( "CustomLayoutRows", m_ui->layoutRowsSpin->value() );
|
||||
|
||||
m_ui->shortcutEditor->save();
|
||||
|
@ -172,7 +172,7 @@ void DesktopGridEffectConfig::defaults()
|
|||
m_ui->zoomDurationSpin->setValue( 0 );
|
||||
m_ui->borderWidthSpin->setValue( 10 );
|
||||
m_ui->desktopNameAlignmentCombo->setCurrentIndex( 0 );
|
||||
m_ui->layoutBox->setCheckState( Qt::Unchecked );
|
||||
m_ui->layoutCombo->setCurrentIndex( int( DesktopGridEffect::LayoutPager ));
|
||||
m_ui->layoutRowsSpin->setValue( 2 );
|
||||
m_ui->shortcutEditor->allDefault();
|
||||
emit changed(true);
|
||||
|
@ -180,7 +180,7 @@ void DesktopGridEffectConfig::defaults()
|
|||
|
||||
void DesktopGridEffectConfig::layoutSelectionChanged()
|
||||
{
|
||||
if( m_ui->layoutBox->checkState() == Qt::Checked )
|
||||
if( m_ui->layoutCombo->currentIndex() == DesktopGridEffect::LayoutCustom )
|
||||
{
|
||||
m_ui->layoutRowsLabel->setEnabled( true );
|
||||
m_ui->layoutRowsSpin->setEnabled( true );
|
||||
|
|
|
@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <kcmodule.h>
|
||||
|
||||
#include "ui_desktopgrid_config.h"
|
||||
#include "desktopgrid.h"
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
|
|
@ -79,10 +79,32 @@
|
|||
<widget class="QComboBox" name="desktopNameAlignmentCombo" />
|
||||
</item>
|
||||
<item row="7" column="0" >
|
||||
<widget class="QCheckBox" name="layoutBox" >
|
||||
<widget class="QLabel" name="label_7" >
|
||||
<property name="text" >
|
||||
<string>Custom grid &layout</string>
|
||||
<string>&Layout mode:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>desktopNameAlignmentCombo</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1" >
|
||||
<widget class="QComboBox" name="layoutCombo" >
|
||||
<item>
|
||||
<property name="text" >
|
||||
<string>Pager</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text" >
|
||||
<string>Automatic</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text" >
|
||||
<string>Custom</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0" >
|
||||
|
@ -173,8 +195,9 @@
|
|||
<tabstop>zoomDurationSpin</tabstop>
|
||||
<tabstop>borderWidthSpin</tabstop>
|
||||
<tabstop>desktopNameAlignmentCombo</tabstop>
|
||||
<tabstop>layoutBox</tabstop>
|
||||
<tabstop>layoutCombo</tabstop>
|
||||
<tabstop>layoutRowsSpin</tabstop>
|
||||
<tabstop>screenEdgeCombo</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
Loading…
Reference in a new issue