mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
krunner: drop it
some runners KCMs are not very flexible I see.. Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
342a4a2f19
commit
cdf4c17926
69 changed files with 54 additions and 6796 deletions
|
@ -271,7 +271,6 @@ add_subdirectory(ksysguard)
|
|||
|
||||
add_subdirectory(kcontrol)
|
||||
add_subdirectory(kmenuedit)
|
||||
add_subdirectory(krunner)
|
||||
add_subdirectory(kinfocenter)
|
||||
|
||||
add_subdirectory(kcminit)
|
||||
|
|
|
@ -84,10 +84,6 @@ Name[zh_CN]=三个修饰键的 KDE 默认值
|
|||
Name[zh_TW]=KDE 預設 3 個變更鍵
|
||||
Uses Win Modifier=false
|
||||
|
||||
[krunner][Global Shortcuts]
|
||||
Run Command=Alt+F2
|
||||
Show System Activity=Ctrl+Esc
|
||||
|
||||
[ksmserver][Global Shortcuts]
|
||||
Halt Without Confirmation=none
|
||||
Log Out Without Confirmation=none
|
||||
|
@ -158,3 +154,6 @@ Window to Previous Desktop=none
|
|||
|
||||
[kxkb][Global Shortcuts]
|
||||
Switch to Next Keyboard Layout=Ctrl+Alt+K
|
||||
|
||||
[kickoff][Global Shortcuts]
|
||||
Run Command=Alt+F2
|
||||
|
|
|
@ -84,10 +84,6 @@ Name[zh_CN]=四个修饰键的 KDE 默认值
|
|||
Name[zh_TW]=KDE 預設 4 個變更鍵
|
||||
Uses Win Modifier=true
|
||||
|
||||
[krunner][Global Shortcuts]
|
||||
Run Command=Meta+Return; Alt+F2
|
||||
Show System Activity=Meta+Ctrl+Pause
|
||||
|
||||
[ksmserver][Global Shortcuts]
|
||||
Halt Without Confirmation=none
|
||||
Log Out Without Confirmation=none
|
||||
|
@ -158,3 +154,7 @@ Window to Previous Desktop=none
|
|||
|
||||
[kxkb][Global Shortcuts]
|
||||
Switch to Next Keyboard Layout=Meta+Ctrl+K
|
||||
|
||||
[kickoff][Global Shortcuts]
|
||||
Run Command=Meta+Return; Alt+F2
|
||||
|
||||
|
|
|
@ -89,10 +89,6 @@ Name[zh_CN]=Mac 方案
|
|||
Name[zh_TW]=Mac 機制
|
||||
Uses Win Modifier=true
|
||||
|
||||
[krunner][Global Shortcuts]
|
||||
Run Command=Alt+F2
|
||||
Show System Activity=Ctrl+Esc
|
||||
|
||||
[ksmserver][Global Shortcuts]
|
||||
Halt Without Confirmation=none
|
||||
Log Out Without Confirmation=none
|
||||
|
@ -163,3 +159,6 @@ Window to Previous Desktop=none
|
|||
|
||||
[kxkb][Global Shortcuts]
|
||||
Switch to Next Keyboard Layout=Ctrl+Alt+K
|
||||
|
||||
[kickoff][Global Shortcuts]
|
||||
Run Command=Alt+F2
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
||||
foreach my $file( @ARGV )
|
||||
{
|
||||
print STDERR "Working on $file\n";
|
||||
|
||||
open(my $FILEHD, $file) or do
|
||||
{
|
||||
print STDERR "Failed to open $file : $!";
|
||||
next;
|
||||
};
|
||||
|
||||
open(my $NEWHD, ">new_$file") or do
|
||||
{
|
||||
print STDERR "Failed to open new_$file : $!";
|
||||
next;
|
||||
};
|
||||
|
||||
open(my $OLDHD, ">old_$file") or do
|
||||
{
|
||||
print STDERR "Failed to open old_$file : $!";
|
||||
next;
|
||||
};
|
||||
|
||||
my $process = 0;
|
||||
my @kwin;
|
||||
my @krunner;
|
||||
my @kxkb;
|
||||
for( <$FILEHD> )
|
||||
{
|
||||
/\[Settings\]/ and do { print $NEWHD $_; next; };
|
||||
/Name(\[[a-zA-Z_@]*\])?/ and do { print $NEWHD $_; next; };
|
||||
/Name\[x-test\]/ and do { print $NEWHD $_; next; };
|
||||
/Uses Win Modifier/ and do { print $NEWHD $_; next; };
|
||||
|
||||
/\[Global Shortcuts\]/ and do { print $OLDHD $_; $process = 1; next; };
|
||||
/\[Shortcuts\]/ and do { print $OLDHD $_; $process = 0; next; };
|
||||
|
||||
s/Alt\+Ctrl/Ctrl+Alt/;
|
||||
s/Delete/Del/;
|
||||
s/Escape/Esc/;
|
||||
s/Win/Meta/;
|
||||
|
||||
if ($process)
|
||||
{
|
||||
/Desktop Screenshot=/ and do { s/Desktop Screenshot=/Desktop Screenshot to Clipboard=/; push @kwin, $_; next; };
|
||||
/Kill Window=/ and do { push @kwin, $_; next; };
|
||||
/Mouse Emulation/ and do { push @kwin, $_; next; };
|
||||
/Switch to Desktop [0-9]+/ and do { push @kwin, $_; next; };
|
||||
/Switch to (Next|Previous) Desktop=/ and do { push @kwin, $_; next; };
|
||||
/Switch One Desktop / and do { push @kwin, $_; next; };
|
||||
/Toggle Window Raise\/Lower=/ and do { push @kwin, $_; next; };
|
||||
/Walk Through Desktop/ and do { push @kwin, $_; next; };
|
||||
/Walk Through Windows/ and do { push @kwin, $_; next; };
|
||||
/Window to (Next |Previous )?Desktop/ and do { push @kwin, $_; next; };
|
||||
/Window (Close|Minimize|Lower|Move|Raise|Resize|Shade)/ and do { push @kwin, $_; next; };
|
||||
/Window Maximize/ and do { push @kwin, $_; next; };
|
||||
/Window Operations Menu=/ and do { s/Window Screenshot=/Window Screenshot to Clipboard=/; push @kwin, $_; next; };
|
||||
/Window Screenshot=/ and do { s/Window Screenshot=/Window Screenshot to Clipboard=/; push @kwin, $_; next; };
|
||||
|
||||
/Switch to Next Keyboard Layout/ and do { push @kxkb, $_; next; };
|
||||
|
||||
/Halt without Confirmation/ and do { s/Halt without Confirmation/Halt Without Confirmation/; push @krunner, $_; next; };
|
||||
/Lock Session/ and do { push @krunner, $_; next; };
|
||||
/Log Out/ and do { push @krunner, $_; next; };
|
||||
/Log Out Without Confirmation/ and do { push @krunner, $_; next; };
|
||||
/Lock Session/ and do { push @krunner, $_; next; };
|
||||
/Reboot without Confirmation/ and do { s/Reboot without Confirmation/Reboot Without Confirmation/; push @krunner, $_; next; };
|
||||
/Run Command/ and do { push @krunner, $_; next; };
|
||||
/Show Taskmanager/ and do { s/Show Taskmanager/Show System Activity/; push @krunner, $_; next; };
|
||||
}
|
||||
|
||||
print $OLDHD $_;
|
||||
}
|
||||
|
||||
print $NEWHD "\n[krunner][Global Shortcuts]\n";
|
||||
print $NEWHD sort @krunner;
|
||||
print $NEWHD "\n[kwin][Global Shortcuts]\n";
|
||||
print $NEWHD sort @kwin;
|
||||
print $NEWHD "\n[kxkb][Global Shortcuts]\n";
|
||||
print $NEWHD sort @kxkb;
|
||||
|
||||
close($FILEHD) or do
|
||||
{
|
||||
print STDERR "Failed to close $file : $!";
|
||||
next;
|
||||
};
|
||||
|
||||
close($NEWHD) or do
|
||||
{
|
||||
print STDERR "Failed to close new_$file : $!";
|
||||
next;
|
||||
};
|
||||
|
||||
close($OLDHD) or do
|
||||
{
|
||||
print STDERR "Failed to close old_$file : $!";
|
||||
next;
|
||||
};
|
||||
}
|
|
@ -89,10 +89,6 @@ Name[zh_CN]=Unix 方案
|
|||
Name[zh_TW]=UNIX 機制
|
||||
Uses Win Modifier=false
|
||||
|
||||
[krunner][Global Shortcuts]
|
||||
Run Command=Alt+F2
|
||||
Show System Activity=Ctrl+Esc
|
||||
|
||||
[ksmserver][Global Shortcuts]
|
||||
Halt Without Confirmation=none
|
||||
Log Out Without Confirmation=none
|
||||
|
@ -163,3 +159,7 @@ Window to Previous Desktop=none
|
|||
|
||||
[kxkb][Global Shortcuts]
|
||||
Switch to Next Keyboard Layout=Ctrl+Alt+K
|
||||
|
||||
[kickoff][Global Shortcuts]
|
||||
Run Command=Alt+F2
|
||||
|
||||
|
|
|
@ -88,10 +88,6 @@ Name[zh_CN]=Windows 方案(无 Win 键)
|
|||
Name[zh_TW]=Windows 機制(沒有 Win 鍵)
|
||||
Uses Win Modifier=false
|
||||
|
||||
[krunner][Global Shortcuts]
|
||||
Run Command=none
|
||||
Show System Activity=Ctrl+Alt+Del
|
||||
|
||||
[ksmserver][Global Shortcuts]
|
||||
Halt Without Confirmation=none
|
||||
Log Out Without Confirmation=none
|
||||
|
@ -162,3 +158,6 @@ Window to Previous Desktop=none
|
|||
|
||||
[kxkb][Global Shortcuts]
|
||||
Switch to Next Keyboard Layout=Ctrl+Alt+K
|
||||
|
||||
[kickoff][Global Shortcuts]
|
||||
Run Command=none
|
||||
|
|
|
@ -88,10 +88,6 @@ Name[zh_CN]=Windows 方案(有 Win 键)
|
|||
Name[zh_TW]=Windows 機制(有 Win 鍵)
|
||||
Uses Win Modifier=true
|
||||
|
||||
[krunner][Global Shortcuts]
|
||||
Run Command=Meta+R
|
||||
Show System Activity=Ctrl+Alt+Del
|
||||
|
||||
[ksmserver][Global Shortcuts]
|
||||
Halt Without Confirmation=none
|
||||
Log Out Without Confirmation=none
|
||||
|
@ -162,3 +158,7 @@ Window to Previous Desktop=none
|
|||
|
||||
[kxkb][Global Shortcuts]
|
||||
Switch to Next Keyboard Layout=Ctrl+Alt+K
|
||||
|
||||
[kickoff][Global Shortcuts]
|
||||
Run Command=Meta+R
|
||||
|
||||
|
|
|
@ -83,10 +83,6 @@ Name[x-test]=xxWindowMaker (3 Modifier Keys)xx
|
|||
Name[zh_CN]=WindowMaker (三个修饰键)
|
||||
Name[zh_TW]=WindowMaker(3 個變更鍵)
|
||||
|
||||
[krunner][Global Shortcuts]
|
||||
Run Command=Alt+F2
|
||||
Show System Activity=Ctrl+Esc
|
||||
|
||||
[ksmserver][Global Shortcuts]
|
||||
Halt Without Confirmation=none
|
||||
Log Out Without Confirmation=none
|
||||
|
@ -157,3 +153,6 @@ Window to Previous Desktop=none
|
|||
|
||||
[kxkb][Global Shortcuts]
|
||||
Switch to Next Keyboard Layout=Ctrl+Alt+K
|
||||
|
||||
[kickoff][Global Shortcuts]
|
||||
Run Command=Alt+F2
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
add_definitions(-DKDE_DEFAULT_DEBUG_AREA=1207)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_SOURCE_DIR}/libs/ksysguard
|
||||
${CMAKE_SOURCE_DIR}/libs/ksysguard/processcore
|
||||
${CMAKE_SOURCE_DIR}/libs/plasmagenericshell
|
||||
# for plasmagenericshell_export.h
|
||||
${CMAKE_BINARY_DIR}/libs/plasmagenericshell
|
||||
# for kworkspace_export.h
|
||||
${CMAKE_BINARY_DIR}/libs/kworkspace
|
||||
)
|
||||
|
||||
set(krunner_KCFG_SRCS kcfg/krunnersettings.kcfgc)
|
||||
set(krunner_dbusAppXML dbus/org.kde.krunner.App.xml)
|
||||
|
||||
|
||||
set(default_interface_SRCS
|
||||
interfaces/default/interface.cpp
|
||||
interfaces/default/resultitem.cpp
|
||||
interfaces/default/resultscene.cpp
|
||||
interfaces/default/resultview.cpp
|
||||
interfaces/default/krunnerhistorycombobox.cpp
|
||||
interfaces/default/selectionbar.cpp
|
||||
)
|
||||
|
||||
set(quicksand_interface_SRCS
|
||||
interfaces/quicksand/qs_completionbox.cpp
|
||||
interfaces/quicksand/qs_dialog.cpp
|
||||
interfaces/quicksand/qs_matchitem.cpp
|
||||
interfaces/quicksand/qs_matchview.cpp
|
||||
interfaces/quicksand/qs_queryactionitem.cpp
|
||||
interfaces/quicksand/qs_querymatchitem.cpp
|
||||
interfaces/quicksand/qs_statusbar.cpp)
|
||||
|
||||
set(krunner_SRCS
|
||||
krunnerdialog.cpp
|
||||
configdialog.cpp
|
||||
krunnerapp.cpp
|
||||
main.cpp
|
||||
${default_interface_SRCS}
|
||||
${quicksand_interface_SRCS}
|
||||
)
|
||||
|
||||
kde4_add_kcfg_files(krunner_SRCS ${krunner_KCFG_SRCS})
|
||||
|
||||
qt4_add_dbus_adaptor(krunner_SRCS ${krunner_dbusAppXML} krunnerapp.h KRunnerApp)
|
||||
|
||||
kde4_add_dbus_service(dbus/org.kde.krunner.service.in)
|
||||
|
||||
set(krunner_SRCS
|
||||
${krunner_SRCS}
|
||||
ksystemactivitydialog.cpp
|
||||
)
|
||||
|
||||
add_executable(krunner ${krunner_SRCS})
|
||||
|
||||
target_link_libraries(krunner
|
||||
KDE4::plasma
|
||||
${KDE4_SOLID_LIBRARIES}
|
||||
KDE4::kdeui
|
||||
KDE4::kcmutils
|
||||
${X11_X11_LIB}
|
||||
kworkspace
|
||||
plasmagenericshell
|
||||
processui
|
||||
)
|
||||
|
||||
if(X11_Xcursor_FOUND)
|
||||
target_link_libraries(krunner ${X11_Xcursor_LIB})
|
||||
endif()
|
||||
|
||||
install(
|
||||
TARGETS krunner
|
||||
DESTINATION ${KDE4_BIN_INSTALL_DIR}
|
||||
)
|
||||
|
||||
install(
|
||||
FILES krunner.desktop
|
||||
DESTINATION ${KDE4_AUTOSTART_INSTALL_DIR}
|
||||
)
|
||||
install(
|
||||
FILES ${krunner_dbusAppXML}
|
||||
DESTINATION ${KDE4_DBUS_INTERFACES_INSTALL_DIR}
|
||||
)
|
|
@ -1 +0,0 @@
|
|||
Code in this application must follow the kdelibs style.
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/bash
|
||||
$EXTRACTRC kcfg/*.kcfg *.ui >> rc.cpp
|
||||
$XGETTEXT `find . -name \*.cpp -o -name \*.h -o -name \*.cc` -o $podir/krunner.pot
|
||||
rm -f rc.cpp
|
|
@ -1,171 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 Ryan P. Bitanga <ryan.bitanga@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, 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 Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "configdialog.h"
|
||||
|
||||
#include <QButtonGroup>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGroupBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QTabWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTimer>
|
||||
|
||||
#include <KConfigGroup>
|
||||
#include <KDebug>
|
||||
#include <KGlobal>
|
||||
#include <KPluginInfo>
|
||||
#include <KPluginSelector>
|
||||
#include <KServiceTypeTrader>
|
||||
|
||||
#include <Plasma/RunnerManager>
|
||||
#include <Plasma/Theme>
|
||||
|
||||
#include "interfaces/default/interface.h"
|
||||
#include "krunnersettings.h"
|
||||
#include "interfaces/quicksand/qs_dialog.h"
|
||||
|
||||
KRunnerConfigWidget::KRunnerConfigWidget(Plasma::RunnerManager *manager, QWidget *parent)
|
||||
: QWidget(parent),
|
||||
m_preview(0),
|
||||
m_manager(manager)
|
||||
{
|
||||
m_tabWidget = new KTabWidget(this);
|
||||
m_sel = new KPluginSelector(m_tabWidget);
|
||||
m_tabWidget->addTab(m_sel, i18n("Plugins"));
|
||||
|
||||
QWidget *m_generalSettings = new QWidget(m_tabWidget);
|
||||
//QVBoxLayout *genLayout = new QVBoxLayout(m_generalSettings);
|
||||
|
||||
m_interfaceType = KRunnerSettings::interface();
|
||||
m_uiOptions.setupUi(m_generalSettings);
|
||||
|
||||
syncPalette();
|
||||
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(syncPalette()));
|
||||
|
||||
QButtonGroup *positionButtons = new QButtonGroup(m_generalSettings);
|
||||
positionButtons->addButton(m_uiOptions.topEdgeButton);
|
||||
positionButtons->addButton(m_uiOptions.freeFloatingButton);
|
||||
m_uiOptions.freeFloatingButton->setChecked(KRunnerSettings::freeFloating());
|
||||
|
||||
QButtonGroup *displayButtons = new QButtonGroup(m_generalSettings);
|
||||
connect(displayButtons, SIGNAL(buttonClicked(int)), this, SLOT(setInterface(int)));
|
||||
displayButtons->addButton(m_uiOptions.commandButton, KRunnerSettings::EnumInterface::CommandOriented);
|
||||
displayButtons->addButton(m_uiOptions.taskButton, KRunnerSettings::EnumInterface::TaskOriented);
|
||||
|
||||
if (m_interfaceType == KRunnerSettings::EnumInterface::CommandOriented) {
|
||||
m_uiOptions.commandButton->setChecked(true);
|
||||
} else {
|
||||
m_uiOptions.taskButton->setChecked(true);
|
||||
}
|
||||
|
||||
connect(m_uiOptions.previewButton, SIGNAL(clicked()), this, SLOT(previewInterface()));
|
||||
|
||||
m_tabWidget->addTab(m_generalSettings, i18n("User Interface"));
|
||||
|
||||
connect(m_sel, SIGNAL(configCommitted(QByteArray)), this, SLOT(updateRunner(QByteArray)));
|
||||
|
||||
QTimer::singleShot(0, this, SLOT(load()));
|
||||
|
||||
m_buttons = new QDialogButtonBox(this);
|
||||
m_buttons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel);
|
||||
connect(m_buttons, SIGNAL(clicked(QAbstractButton*)), this, SLOT(save(QAbstractButton*)));
|
||||
connect(m_buttons, SIGNAL(rejected()), this, SIGNAL(finished()));
|
||||
|
||||
QVBoxLayout *topLayout = new QVBoxLayout(this);
|
||||
topLayout->addWidget(m_tabWidget);
|
||||
topLayout->addWidget(m_buttons);
|
||||
}
|
||||
|
||||
KRunnerConfigWidget::~KRunnerConfigWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void KRunnerConfigWidget::syncPalette()
|
||||
{
|
||||
QColor color = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
|
||||
QPalette p = palette();
|
||||
p.setColor(QPalette::Normal, QPalette::WindowText, color);
|
||||
p.setColor(QPalette::Inactive, QPalette::WindowText, color);
|
||||
color.setAlphaF(0.6);
|
||||
p.setColor(QPalette::Disabled, QPalette::WindowText, color);
|
||||
|
||||
p.setColor(QPalette::Normal, QPalette::Link, Plasma::Theme::defaultTheme()->color(Plasma::Theme::LinkColor));
|
||||
p.setColor(QPalette::Normal, QPalette::LinkVisited, Plasma::Theme::defaultTheme()->color(Plasma::Theme::VisitedLinkColor));
|
||||
setPalette(p);
|
||||
}
|
||||
|
||||
void KRunnerConfigWidget::previewInterface()
|
||||
{
|
||||
delete m_preview;
|
||||
switch (m_interfaceType) {
|
||||
case KRunnerSettings::EnumInterface::CommandOriented:
|
||||
m_preview = new Interface(m_manager, this);
|
||||
break;
|
||||
default:
|
||||
m_preview = new QsDialog(m_manager, this);
|
||||
break;
|
||||
}
|
||||
|
||||
m_preview->setFreeFloating(m_uiOptions.freeFloatingButton->isChecked());
|
||||
m_preview->show();
|
||||
}
|
||||
|
||||
void KRunnerConfigWidget::setInterface(int type)
|
||||
{
|
||||
m_interfaceType = type;
|
||||
}
|
||||
|
||||
void KRunnerConfigWidget::updateRunner(const QByteArray &name)
|
||||
{
|
||||
Plasma::AbstractRunner *runner = m_manager->runner(QString::fromLatin1( name ));
|
||||
//Update runner if runner is loaded
|
||||
if (runner) {
|
||||
runner->reloadConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerConfigWidget::load()
|
||||
{
|
||||
m_sel->addPlugins(Plasma::RunnerManager::listRunnerInfo(),
|
||||
KPluginSelector::ReadConfigFile,
|
||||
i18n("Available Plugins"), QString(),
|
||||
KSharedConfig::openConfig(QLatin1String( "krunnerrc" )));
|
||||
}
|
||||
|
||||
void KRunnerConfigWidget::save(QAbstractButton *pushed)
|
||||
{
|
||||
if (m_buttons->buttonRole(pushed) == QDialogButtonBox::ApplyRole ||
|
||||
m_buttons->buttonRole(pushed) == QDialogButtonBox::AcceptRole) {
|
||||
m_sel->save();
|
||||
m_manager->reloadConfiguration();
|
||||
KRunnerSettings::setInterface(m_interfaceType);
|
||||
KRunnerSettings::setFreeFloating(m_uiOptions.freeFloatingButton->isChecked());
|
||||
KRunnerSettings::self()->writeConfig();
|
||||
|
||||
if (m_buttons->buttonRole(pushed) == QDialogButtonBox::AcceptRole) {
|
||||
emit finished();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_configdialog.cpp"
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 Ryan P. Bitanga <ryan.bitanga@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, 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 Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KRUNNERCONFIG_H
|
||||
#define KRUNNERCONFIG_H
|
||||
|
||||
|
||||
#include <KTabWidget>
|
||||
|
||||
#include "ui_interfaceOptions.h"
|
||||
|
||||
class KRunnerDialog;
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QTabWidget>
|
||||
|
||||
class KPluginSelector;
|
||||
|
||||
namespace Plasma {
|
||||
class RunnerManager;
|
||||
}
|
||||
|
||||
class KRunnerConfigWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KRunnerConfigWidget(Plasma::RunnerManager *manager, QWidget *parent = 0);
|
||||
~KRunnerConfigWidget();
|
||||
|
||||
Q_SIGNALS:
|
||||
void finished();
|
||||
|
||||
private slots:
|
||||
void load();
|
||||
void save(QAbstractButton *pushed);
|
||||
void previewInterface();
|
||||
void setInterface(int type);
|
||||
void updateRunner(const QByteArray& runnerName);
|
||||
void syncPalette();
|
||||
|
||||
private:
|
||||
int m_interfaceType;
|
||||
KRunnerDialog *m_preview;
|
||||
KPluginSelector *m_sel;
|
||||
KTabWidget *m_tabWidget;
|
||||
QDialogButtonBox *m_buttons;
|
||||
Plasma::RunnerManager *m_manager;
|
||||
Ui::InterfaceOptions m_uiOptions;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="org.kde.krunner.App">
|
||||
<method name="showTaskManager">
|
||||
</method>
|
||||
<method name="showTaskManagerWithFilter">
|
||||
<arg name="filterText" type="s" direction="in"/>
|
||||
</method>
|
||||
<method name="display">
|
||||
</method>
|
||||
<method name="displaySingleRunner">
|
||||
<arg name="runnerName" type="s" direction="in"/>
|
||||
</method>
|
||||
<method name="displayWithClipboardContents">
|
||||
</method>
|
||||
<method name="query">
|
||||
<arg name="term" type="s" direction="in"/>
|
||||
</method>
|
||||
<method name="querySingleRunner">
|
||||
<arg name="runnerName" type="s" direction="in"/>
|
||||
<arg name="term" type="s" direction="in"/>
|
||||
</method>
|
||||
<method name="switchUser">
|
||||
</method>
|
||||
<method name="clearHistory">
|
||||
</method>
|
||||
<method name="singleModeAdvertisedRunnerIds">
|
||||
<arg type="as" direction="out"/>
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
|
@ -1,4 +0,0 @@
|
|||
[D-BUS Service]
|
||||
Name=org.kde.krunner
|
||||
Exec=@KDE4_BIN_INSTALL_DIR@/krunner
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>InterfaceOptions</class>
|
||||
<widget class="QWidget" name="InterfaceOptions">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>237</width>
|
||||
<height>137</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Positioning:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QRadioButton" name="topEdgeButton">
|
||||
<property name="text">
|
||||
<string>Top edge of screen</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QRadioButton" name="freeFloatingButton">
|
||||
<property name="text">
|
||||
<string>Free floating window</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>69</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Style:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QRadioButton" name="commandButton">
|
||||
<property name="text">
|
||||
<string>Command oriented</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QRadioButton" name="taskButton">
|
||||
<property name="text">
|
||||
<string>Task oriented</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QPushButton" name="previewButton">
|
||||
<property name="text">
|
||||
<string>Preview</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -1,664 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2006 by Aaron Seigo <aseigo@kde.org> *
|
||||
* Copyright 2008 by Davide Bettio <davide.bettio@kdemail.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; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDesktopWidget>
|
||||
#include <QGraphicsView>
|
||||
#include <QHBoxLayout>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QLabel>
|
||||
#include <QShortcut>
|
||||
#include <QToolButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <KAction>
|
||||
#include <KActionCollection>
|
||||
#include <KHistoryComboBox>
|
||||
#include <KCompletion>
|
||||
#include <KCompletionBox>
|
||||
#include <KDebug>
|
||||
#include <KDialog>
|
||||
#include <KLineEdit>
|
||||
#include <KLocale>
|
||||
#include <KGlobalSettings>
|
||||
#include <KPushButton>
|
||||
#include <KStyle>
|
||||
#include <KTitleWidget>
|
||||
#include <KWindowSystem>
|
||||
|
||||
#include <Plasma/AbstractRunner>
|
||||
#include <Plasma/RunnerManager>
|
||||
#include <Plasma/Theme>
|
||||
#include <Plasma/Svg>
|
||||
|
||||
#include "krunnerapp.h"
|
||||
#include "krunnersettings.h"
|
||||
#include "interfaces/default/resultscene.h"
|
||||
#include "interfaces/default/resultitem.h"
|
||||
#include "interfaces/default/krunnerhistorycombobox.h"
|
||||
#include "interfaces/default/resultview.h"
|
||||
#include "toolbutton.h"
|
||||
|
||||
static const int MIN_WIDTH = 420;
|
||||
|
||||
Interface::Interface(Plasma::RunnerManager *runnerManager, QWidget *parent)
|
||||
: KRunnerDialog(runnerManager, parent),
|
||||
m_delayedRun(false),
|
||||
m_running(false),
|
||||
m_queryRunning(false)
|
||||
{
|
||||
m_resultData.processHoverEvents = true;
|
||||
m_resultData.mouseHovering = false;
|
||||
m_resultData.runnerManager = runnerManager;
|
||||
|
||||
m_hideResultsTimer.setSingleShot(true);
|
||||
connect(&m_hideResultsTimer, SIGNAL(timeout()), this, SLOT(hideResultsArea()));
|
||||
|
||||
m_reenableHoverEventsTimer.setSingleShot(true);
|
||||
m_reenableHoverEventsTimer.setInterval(50);
|
||||
connect(&m_reenableHoverEventsTimer, SIGNAL(timeout()), this, SLOT(reenableHoverEvents()));
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->setMargin(0);
|
||||
|
||||
m_buttonContainer = new QWidget(this);
|
||||
QHBoxLayout *bottomLayout = new QHBoxLayout(m_buttonContainer);
|
||||
bottomLayout->setMargin(0);
|
||||
|
||||
m_configButton = new ToolButton(m_buttonContainer);
|
||||
m_configButton->setText(i18n("Settings"));
|
||||
m_configButton->setToolTip(i18n("Settings"));
|
||||
connect(m_configButton, SIGNAL(clicked()), SLOT(toggleConfigDialog()));
|
||||
bottomLayout->addWidget(m_configButton);
|
||||
|
||||
//Set up the system activity button, using the krunner global action, showing the global shortcut in the tooltip
|
||||
m_activityButton = new ToolButton(m_buttonContainer);
|
||||
KRunnerApp *krunnerApp = KRunnerApp::self();
|
||||
QAction *showSystemActivityAction = krunnerApp->actionCollection()->action(QLatin1String( "Show System Activity" ));
|
||||
m_activityButton->setDefaultAction(showSystemActivityAction);
|
||||
|
||||
updateSystemActivityToolTip();
|
||||
connect(showSystemActivityAction, SIGNAL(globalShortcutChanged(QKeySequence)), this, SLOT(updateSystemActivityToolTip()));
|
||||
connect(showSystemActivityAction, SIGNAL(triggered(bool)), this, SLOT(resetAndClose()));
|
||||
bottomLayout->addWidget(m_activityButton);
|
||||
|
||||
m_singleRunnerIcon = new QLabel();
|
||||
bottomLayout->addWidget(m_singleRunnerIcon);
|
||||
m_singleRunnerDisplayName = new QLabel();
|
||||
bottomLayout->addWidget(m_singleRunnerDisplayName);
|
||||
|
||||
m_helpButton = new ToolButton(m_buttonContainer);
|
||||
m_helpButton->setText(i18n("Help"));
|
||||
m_helpButton->setToolTip(i18n("Information on using this application"));
|
||||
connect(m_helpButton, SIGNAL(clicked(bool)), SLOT(showHelp()));
|
||||
connect(m_helpButton, SIGNAL(clicked(bool)), SLOT(configCompleted()));
|
||||
bottomLayout->addWidget(m_helpButton);
|
||||
|
||||
QSpacerItem* closeButtonSpacer = new QSpacerItem(0,0,QSizePolicy::MinimumExpanding,QSizePolicy::Fixed);
|
||||
bottomLayout->addSpacerItem(closeButtonSpacer);
|
||||
|
||||
m_closeButton = new ToolButton(m_buttonContainer);
|
||||
KGuiItem guiItem = KStandardGuiItem::close();
|
||||
m_closeButton->setText(guiItem.text());
|
||||
m_closeButton->setToolTip(guiItem.text().remove(QLatin1Char( '&' )));
|
||||
connect(m_closeButton, SIGNAL(clicked(bool)), SLOT(resetAndClose()));
|
||||
bottomLayout->addWidget(m_closeButton);
|
||||
|
||||
m_layout->addWidget(m_buttonContainer);
|
||||
|
||||
m_searchTerm = new KrunnerHistoryComboBox(false, this);
|
||||
|
||||
KLineEdit *lineEdit = new KLineEdit(m_searchTerm);
|
||||
QAction *focusEdit = new QAction(this);
|
||||
focusEdit->setShortcut(Qt::Key_F6);
|
||||
|
||||
connect(focusEdit, SIGNAL(triggered(bool)), this, SLOT(searchTermSetFocus()));
|
||||
addAction(focusEdit);
|
||||
|
||||
// the order of these next few lines if very important.
|
||||
// QComboBox::setLineEdit sets the autoComplete flag on the lineedit,
|
||||
// and KComboBox::setAutoComplete resets the autocomplete mode! ugh!
|
||||
m_searchTerm->setLineEdit(lineEdit);
|
||||
|
||||
m_completion = new KCompletion();
|
||||
lineEdit->setCompletionObject(m_completion);
|
||||
lineEdit->setCompletionMode(static_cast<KGlobalSettings::Completion>(KRunnerSettings::queryTextCompletionMode()));
|
||||
lineEdit->setClearButtonShown(true);
|
||||
QStringList pastQueryItems = KRunnerSettings::pastQueries();
|
||||
m_searchTerm->setHistoryItems(pastQueryItems);
|
||||
m_completion->insertItems(pastQueryItems);
|
||||
bottomLayout->insertWidget(4, m_searchTerm, 10);
|
||||
|
||||
m_singleRunnerSearchTerm = new KLineEdit(this);
|
||||
bottomLayout->insertWidget(4, m_singleRunnerSearchTerm, 10 );
|
||||
|
||||
//kDebug() << "size:" << m_resultsView->size() << m_resultsView->minimumSize();
|
||||
m_resultsScene = new ResultScene(&m_resultData, runnerManager, m_searchTerm, this);
|
||||
m_resultsView = new ResultsView(m_resultsScene, &m_resultData, this);
|
||||
m_layout->addWidget(m_resultsView);
|
||||
|
||||
connect(m_resultsScene, SIGNAL(viewableHeightChanged()), this, SLOT(fitWindow()));
|
||||
connect(m_resultsScene, SIGNAL(matchCountChanged(int)), this, SLOT(matchCountChanged(int)));
|
||||
connect(m_resultsScene, SIGNAL(itemActivated(ResultItem*)), this, SLOT(run(ResultItem*)));
|
||||
|
||||
connect(m_searchTerm, SIGNAL(queryTextEdited(QString)), this, SLOT(queryTextEdited(QString)));
|
||||
connect(m_searchTerm, SIGNAL(returnPressed()), this, SLOT(runDefaultResultItem()));
|
||||
connect(m_singleRunnerSearchTerm, SIGNAL(textChanged(QString)), this, SLOT(queryTextEdited(QString)));
|
||||
connect(m_singleRunnerSearchTerm, SIGNAL(returnPressed()), this, SLOT(runDefaultResultItem()));
|
||||
|
||||
lineEdit->installEventFilter(this);
|
||||
m_searchTerm->installEventFilter(this);
|
||||
|
||||
themeUpdated();
|
||||
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(themeUpdated()));
|
||||
|
||||
new QShortcut(QKeySequence(Qt::Key_Escape), this, SLOT(resetAndClose()));
|
||||
|
||||
m_layout->setAlignment(Qt::AlignTop);
|
||||
|
||||
setTabOrder(0, m_configButton);
|
||||
setTabOrder(m_configButton, m_activityButton);
|
||||
setTabOrder(m_activityButton, m_searchTerm);
|
||||
setTabOrder(m_searchTerm, m_singleRunnerSearchTerm);
|
||||
setTabOrder(m_singleRunnerSearchTerm, m_resultsView);
|
||||
setTabOrder(m_resultsView, m_helpButton);
|
||||
setTabOrder(m_helpButton, m_closeButton);
|
||||
|
||||
//kDebug() << "size:" << m_resultsView->size() << m_resultsView->minimumSize() << minimumSizeHint();
|
||||
|
||||
// we restore the original size, which will set the results view back to its
|
||||
// normal size, then we hide the results view and resize the dialog
|
||||
|
||||
setMinimumSize(QSize(MIN_WIDTH, m_searchTerm->sizeHint().height()));
|
||||
|
||||
// we load the last used size; the saved value is the size of the dialog when the
|
||||
// results are visible;
|
||||
adjustSize();
|
||||
|
||||
if (KGlobal::config()->hasGroup("Interface")) {
|
||||
KConfigGroup interfaceConfig(KGlobal::config(), "Interface");
|
||||
restoreDialogSize(interfaceConfig);
|
||||
m_defaultSize = size();
|
||||
} else {
|
||||
const int screenWidth = qApp->desktop()->screenGeometry().width();
|
||||
int width = size().width();
|
||||
|
||||
if (screenWidth >= 1920) {
|
||||
width = qMax(width, 550);
|
||||
} else if (screenWidth >= 1024) {
|
||||
width = qMax(width, 300);
|
||||
}
|
||||
|
||||
m_defaultSize = QSize(width, 500);
|
||||
}
|
||||
|
||||
m_resultsView->hide();
|
||||
|
||||
m_delayedQueryTimer.setSingleShot(true);
|
||||
m_delayedQueryTimer.setInterval(50);
|
||||
connect(&m_delayedQueryTimer, SIGNAL(timeout()), this, SLOT(delayedQueryLaunch()));
|
||||
|
||||
m_saveDialogSizeTimer.setSingleShot(true);
|
||||
m_saveDialogSizeTimer.setInterval(1000);
|
||||
connect(&m_saveDialogSizeTimer, SIGNAL(timeout()), SLOT(saveCurrentDialogSize()));
|
||||
|
||||
QTimer::singleShot(0, this, SLOT(resetInterface()));
|
||||
}
|
||||
|
||||
bool Interface::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (obj == m_searchTerm->lineEdit() && event->type() == QEvent::MouseButtonPress) {
|
||||
if (KWindowSystem::activeWindow() != winId()) {
|
||||
// this overcomes problems with click-to-focus and being a Dock window
|
||||
KWindowSystem::forceActiveWindow(winId());
|
||||
searchTermSetFocus();
|
||||
}
|
||||
} else if (obj == m_searchTerm && event->type() == QEvent::KeyPress) {
|
||||
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
|
||||
// the comparision between itemText(1) and the currentText is an artifact
|
||||
// of KHistoryComboBox: it sets the combobox to index 1 when using arrow-down
|
||||
// through entries after having arrow-up'd through them and hitting the
|
||||
// last item ... which one would expect to be index 0. index 1 is _also_
|
||||
// the first item in the history at other times, however, so we need to
|
||||
// check if index 1 is indeed the actual item or if item 1 is not the same
|
||||
// the current text. very, very odd. but it works. - aseigo.
|
||||
if (ke->key() == Qt::Key_Down &&
|
||||
(m_searchTerm->currentIndex() < 1 ||
|
||||
(m_searchTerm->currentIndex() == 1 &&
|
||||
m_searchTerm->itemText(1) != m_searchTerm->currentText()))) {
|
||||
m_resultsView->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
return KRunnerDialog::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void Interface::saveDialogSize(KConfigGroup &group)
|
||||
{
|
||||
group.writeEntry("Size", m_defaultSize);
|
||||
}
|
||||
|
||||
void Interface::restoreDialogSize(KConfigGroup &group)
|
||||
{
|
||||
resize(group.readEntry("Size", size()));
|
||||
}
|
||||
|
||||
void Interface::updateSystemActivityToolTip()
|
||||
{
|
||||
/* Set the tooltip for the Show System Activity button to include the global shortcut */
|
||||
KRunnerApp *krunnerApp = KRunnerApp::self();
|
||||
KAction *showSystemActivityAction = qobject_cast<KAction *>(krunnerApp->actionCollection()->action(QLatin1String( "Show System Activity" )));
|
||||
if (showSystemActivityAction) {
|
||||
QString shortcut = showSystemActivityAction->globalShortcut().toString();
|
||||
if (shortcut.isEmpty()) {
|
||||
m_activityButton->setToolTip( showSystemActivityAction->toolTip() );
|
||||
} else {
|
||||
m_activityButton->setToolTip( i18nc("tooltip, shortcut", "%1 (%2)", showSystemActivityAction->toolTip(), shortcut));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Interface::setConfigWidget(QWidget *w)
|
||||
{
|
||||
const int screenId = qApp->desktop()->screenNumber(this);
|
||||
const int maxHeight = qApp->desktop()->availableGeometry(screenId).height();
|
||||
|
||||
int left, top, right, bottom;
|
||||
getContentsMargins(&left, &top, &right, &bottom);
|
||||
const int padding = top + bottom + m_activityButton->height();
|
||||
resize(width(), qMin(maxHeight, qMax(w->sizeHint().height() + padding, m_defaultSize.height())));
|
||||
|
||||
m_resultsView->hide();
|
||||
m_searchTerm->setEnabled(false);
|
||||
m_layout->addWidget(w);
|
||||
|
||||
connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(configWidgetDestroyed()));
|
||||
}
|
||||
|
||||
void Interface::configWidgetDestroyed()
|
||||
{
|
||||
QTimer::singleShot(0, this, SLOT(cleanupAfterConfigWidget()));
|
||||
}
|
||||
|
||||
void Interface::cleanupAfterConfigWidget()
|
||||
{
|
||||
m_searchTerm->setEnabled(true);
|
||||
resetInterface();
|
||||
searchTermSetFocus();
|
||||
}
|
||||
|
||||
void Interface::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
// We set m_defaultSize only when the event is spontaneous, i.e. when the user resizes the
|
||||
// window, or if they are manually resizing it
|
||||
if ((freeFloating() && event->spontaneous()) || manualResizing() != NotResizing) {
|
||||
if (manualResizing() == HorizontalResizing) {
|
||||
m_defaultSize = QSize(size().width(), m_defaultSize.height());
|
||||
} else {
|
||||
m_defaultSize = QSize(m_defaultSize.width(), size().height());
|
||||
}
|
||||
m_saveDialogSizeTimer.start();
|
||||
}
|
||||
|
||||
m_resultsView->resize(m_buttonContainer->width(), m_resultsView->height());
|
||||
m_resultsScene->setWidth(m_resultsView->width());
|
||||
KRunnerDialog::resizeEvent(event);
|
||||
}
|
||||
|
||||
void Interface::saveCurrentDialogSize()
|
||||
{
|
||||
KConfigGroup interfaceConfig(KGlobal::config(), "Interface");
|
||||
saveDialogSize(interfaceConfig);
|
||||
}
|
||||
|
||||
Interface::~Interface()
|
||||
{
|
||||
KRunnerSettings::setPastQueries(m_searchTerm->historyItems());
|
||||
KRunnerSettings::setQueryTextCompletionMode(m_searchTerm->completionMode());
|
||||
KRunnerSettings::self()->writeConfig();
|
||||
|
||||
// Before saving the size we resize to the default size, with the results container shown.
|
||||
resize(m_defaultSize);
|
||||
KConfigGroup interfaceConfig(KGlobal::config(), "Interface");
|
||||
saveCurrentDialogSize();
|
||||
KGlobal::config()->sync();
|
||||
}
|
||||
|
||||
|
||||
void Interface::searchTermSetFocus()
|
||||
{
|
||||
if (m_runnerManager->singleMode()) {
|
||||
m_singleRunnerSearchTerm->setFocus();
|
||||
} else {
|
||||
m_searchTerm->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Interface::themeUpdated()
|
||||
{
|
||||
//reset the icons
|
||||
m_helpButton->setIcon(m_iconSvg->pixmap(QLatin1String( "help" )));
|
||||
m_configButton->setIcon(m_iconSvg->pixmap(QLatin1String( "configure" )));
|
||||
m_activityButton->setIcon(m_iconSvg->pixmap(QLatin1String( "status" )));
|
||||
m_closeButton->setIcon(m_iconSvg->pixmap(QLatin1String( "close" )));
|
||||
}
|
||||
|
||||
void Interface::clearHistory()
|
||||
{
|
||||
m_searchTerm->clearHistory();
|
||||
KRunnerSettings::setPastQueries(m_searchTerm->historyItems());
|
||||
}
|
||||
|
||||
void Interface::display(const QString &term)
|
||||
{
|
||||
if (!term.isEmpty() || !isVisible() ||
|
||||
m_runnerManager->singleMode() != m_singleRunnerIcon->isVisible()) {
|
||||
resetInterface();
|
||||
}
|
||||
|
||||
positionOnScreen();
|
||||
searchTermSetFocus();
|
||||
|
||||
if (m_runnerManager->singleMode()) {
|
||||
if (term.isEmpty()) {
|
||||
// We need to manually trigger queryTextEdited, since
|
||||
// with an empty query it won't be triggered; still we need it
|
||||
// to launch the query
|
||||
queryTextEdited(QString());
|
||||
} else {
|
||||
m_singleRunnerSearchTerm->setText(term);
|
||||
}
|
||||
} else if (!term.isEmpty()) {
|
||||
m_searchTerm->setItemText(0, term);
|
||||
m_searchTerm->setCurrentIndex(0);
|
||||
} else {
|
||||
m_searchTerm->reset();
|
||||
}
|
||||
}
|
||||
|
||||
void Interface::resetInterface()
|
||||
{
|
||||
setStaticQueryMode(false);
|
||||
m_delayedRun = false;
|
||||
m_searchTerm->setCurrentItem(QString(), true, 0);
|
||||
m_singleRunnerSearchTerm->clear();
|
||||
m_resultsScene->queryCleared();
|
||||
if (!m_running) {
|
||||
m_runnerManager->reset();
|
||||
}
|
||||
resetResultsArea();
|
||||
m_minimumHeight = height();
|
||||
}
|
||||
|
||||
void Interface::showHelp()
|
||||
{
|
||||
QMap<QString, Plasma::QueryMatch> matches;
|
||||
QList<Plasma::AbstractRunner*> runnerList;
|
||||
|
||||
Plasma::AbstractRunner *singleRunner = m_runnerManager->singleModeRunner();
|
||||
if (singleRunner) {
|
||||
runnerList << singleRunner;
|
||||
} else {
|
||||
runnerList = m_runnerManager->runners();
|
||||
}
|
||||
|
||||
|
||||
foreach (Plasma::AbstractRunner *runner, runnerList) {
|
||||
int count = 0;
|
||||
QIcon icon(runner->icon());
|
||||
if (icon.isNull()) {
|
||||
icon = KIcon(QLatin1String( "system-run" ));
|
||||
}
|
||||
|
||||
foreach (const Plasma::RunnerSyntax &syntax, runner->syntaxes()) {
|
||||
Plasma::QueryMatch match(0);
|
||||
match.setType(Plasma::QueryMatch::InformationalMatch);
|
||||
match.setIcon(icon);
|
||||
match.setText(syntax.exampleQueriesWithTermDescription().join(QLatin1String( ", " )));
|
||||
match.setSubtext(syntax.description() + QLatin1Char( '\n' ) +
|
||||
i18n("(From %1, %2)", runner->name(), runner->description()));
|
||||
match.setData(syntax.exampleQueries().first());
|
||||
matches.insert(runner->name() + QString::number(++count), match);
|
||||
}
|
||||
}
|
||||
|
||||
m_resultsScene->setQueryMatches(matches.values());
|
||||
}
|
||||
|
||||
void Interface::setStaticQueryMode(bool staticQuery)
|
||||
{
|
||||
// don't show the search and other control buttons in the case of a static querymatch
|
||||
const bool visible = !staticQuery;
|
||||
Plasma::AbstractRunner *singleRunner = m_runnerManager->singleModeRunner();
|
||||
m_configButton->setVisible(visible && !singleRunner);
|
||||
m_activityButton->setVisible(visible && !singleRunner);
|
||||
m_helpButton->setVisible(visible);
|
||||
m_searchTerm->setVisible(visible && !singleRunner);
|
||||
m_singleRunnerSearchTerm->setVisible(visible && singleRunner);
|
||||
if (singleRunner) {
|
||||
m_singleRunnerIcon->setPixmap(singleRunner->icon().pixmap(QSize(22, 22)));
|
||||
m_singleRunnerDisplayName->setText(singleRunner->name());
|
||||
}
|
||||
m_singleRunnerIcon->setVisible(singleRunner);
|
||||
m_singleRunnerDisplayName->setVisible(singleRunner);
|
||||
}
|
||||
|
||||
void Interface::hideEvent(QHideEvent *e)
|
||||
{
|
||||
resetInterface();
|
||||
KRunnerDialog::hideEvent(e);
|
||||
}
|
||||
|
||||
void Interface::run(ResultItem *item)
|
||||
{
|
||||
if (!item || !item->isValid() || item->group() < Plasma::QueryMatch::PossibleMatch) {
|
||||
m_delayedRun = true;
|
||||
return;
|
||||
}
|
||||
|
||||
kDebug() << item->name() << item->id();
|
||||
m_delayedRun = false;
|
||||
|
||||
if (item->group() == Plasma::QueryMatch::InformationalMatch) {
|
||||
QString info = item->data();
|
||||
int editPos = info.length();
|
||||
|
||||
if (!info.isEmpty()) {
|
||||
if (item->isQueryPrototype()) {
|
||||
// lame way of checking to see if this is a Help Button generated match!
|
||||
int index = info.indexOf(QLatin1String( ":q:" ));
|
||||
|
||||
if (index != -1) {
|
||||
editPos = index;
|
||||
info.replace(QLatin1String( ":q:" ), QLatin1String( "" ));
|
||||
}
|
||||
}
|
||||
|
||||
QStringList history = m_searchTerm->historyItems();
|
||||
history.prepend(m_searchTerm->currentText().trimmed());
|
||||
kDebug() << m_searchTerm->currentText() << history;
|
||||
m_searchTerm->setHistoryItems(history);
|
||||
m_searchTerm->setCurrentIndex(0);
|
||||
m_searchTerm->lineEdit()->setText(info);
|
||||
m_searchTerm->lineEdit()->setCursorPosition(editPos);
|
||||
QApplication::clipboard()->setText(info);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO: check if run is succesful before adding the term to history
|
||||
if ((item->group() == Plasma::QueryMatch::CompletionMatch) ||
|
||||
(item->group() == Plasma::QueryMatch::PossibleMatch)) {
|
||||
m_searchTerm->addToHistory(item->name());
|
||||
} else {
|
||||
m_searchTerm->addToHistory(m_searchTerm->currentText().trimmed());
|
||||
}
|
||||
|
||||
m_running = true;
|
||||
// must run the result first before clearing the interface
|
||||
// in a way that will cause the results scene to be cleared and
|
||||
// the RunnerManager to be cleared of context as a result
|
||||
close();
|
||||
item->run(m_runnerManager);
|
||||
m_running = false;
|
||||
|
||||
resetInterface();
|
||||
}
|
||||
|
||||
void Interface::resetAndClose()
|
||||
{
|
||||
resetInterface();
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void Interface::runDefaultResultItem()
|
||||
{
|
||||
if (m_queryRunning) {
|
||||
m_delayedRun = true;
|
||||
} else {
|
||||
run(m_resultsScene->defaultResultItem());
|
||||
}
|
||||
}
|
||||
|
||||
void Interface::queryTextEdited(const QString &query)
|
||||
{
|
||||
if (query.isEmpty() || query.trimmed() != m_runnerManager->query()) {
|
||||
// if the query is empty and the query is NOT what we are currently looking for ... then
|
||||
// reset m_delayedRun. it does happen, however, that a search is being made already for the
|
||||
// query text and this method gets called again, in which case we do NOT want to reset
|
||||
// m_delayedRun
|
||||
m_delayedRun = false;
|
||||
}
|
||||
|
||||
if (query.isEmpty() && !m_runnerManager->singleMode()) {
|
||||
m_delayedQueryTimer.stop();
|
||||
resetInterface();
|
||||
m_queryRunning = false;
|
||||
} else {
|
||||
m_delayedQueryTimer.start();
|
||||
m_queryRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Interface::delayedQueryLaunch()
|
||||
{
|
||||
const QString query = (m_runnerManager->singleMode() ? m_singleRunnerSearchTerm->userText()
|
||||
: static_cast<KLineEdit*>(m_searchTerm->lineEdit())->userText()).trimmed();
|
||||
const QString runnerId = m_runnerManager->singleMode() ? m_runnerManager->singleModeRunnerId() : QString();
|
||||
|
||||
// we want to check if this is a new query or not for the later running of
|
||||
// the default item
|
||||
if (!query.isEmpty() || m_runnerManager->singleMode()) {
|
||||
const bool newQuery = !query.isEmpty() && m_runnerManager->query() != query;
|
||||
m_queryRunning = m_queryRunning || newQuery || !runnerId.isEmpty();
|
||||
m_runnerManager->launchQuery(query, runnerId);
|
||||
}
|
||||
}
|
||||
|
||||
void Interface::matchCountChanged(int count)
|
||||
{
|
||||
m_queryRunning = false;
|
||||
const bool show = count > 0;
|
||||
m_hideResultsTimer.stop();
|
||||
|
||||
if (show && m_delayedRun) {
|
||||
kDebug() << "delayed run with" << count << "items";
|
||||
runDefaultResultItem();
|
||||
return;
|
||||
}
|
||||
|
||||
if (show) {
|
||||
//kDebug() << "showing!" << minimumSizeHint();
|
||||
if (!m_resultsView->isVisible()) {
|
||||
fitWindow();
|
||||
|
||||
// Next 2 lines are a workaround to allow arrow
|
||||
// keys navigation in krunner's result list.
|
||||
// Patch submited in bugreport #211578
|
||||
QEvent event(QEvent::WindowActivate);
|
||||
QApplication::sendEvent(m_resultsView, &event);
|
||||
|
||||
m_resultsView->show();
|
||||
}
|
||||
//m_resultsScene->resize(m_resultsView->width(), qMax(m_resultsView->height(), int(m_resultsScene->height())));
|
||||
//kDebug() << s << size();
|
||||
} else {
|
||||
//kDebug() << "hiding ... eventually";
|
||||
m_delayedRun = false;
|
||||
m_hideResultsTimer.start(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void Interface::reenableHoverEvents()
|
||||
{
|
||||
//kDebug() << "reenabling hover events, for better or worse";
|
||||
m_resultData.processHoverEvents = true;
|
||||
}
|
||||
|
||||
void Interface::fitWindow()
|
||||
{
|
||||
m_resultData.processHoverEvents = false;
|
||||
QSize s = m_defaultSize;
|
||||
const int resultsHeight = m_resultsScene->viewableHeight() + 2;
|
||||
int spacing = m_layout->spacing();
|
||||
if (spacing < 0) {
|
||||
// KStyles allow for variable spacing via the layoutSpacingImplementation() method;
|
||||
// in this case m_layout->spacing() returns -1 and we should ask for the
|
||||
// spacing by ourselves.
|
||||
// This is quite ugly, but at least gives the right guess, so that we avoid
|
||||
// multiple resize events
|
||||
spacing = style()->layoutSpacing(QSizePolicy::DefaultType, QSizePolicy::DefaultType, Qt::Vertical);
|
||||
}
|
||||
|
||||
//kDebug() << m_minimumHeight << resultsHeight << spacing << s.height();
|
||||
|
||||
if (m_minimumHeight + resultsHeight + spacing < s.height()) {
|
||||
s.setHeight(m_minimumHeight + resultsHeight + spacing);
|
||||
m_resultsView->setMinimumHeight(resultsHeight);
|
||||
// The layout will activate on the next event cycle, but
|
||||
// we need to update the minimum size now, as we are going to
|
||||
// resize the krunner window right away.
|
||||
m_layout->activate();
|
||||
}
|
||||
|
||||
resize(s);
|
||||
m_reenableHoverEventsTimer.start();
|
||||
}
|
||||
|
||||
void Interface::hideResultsArea()
|
||||
{
|
||||
searchTermSetFocus();
|
||||
resetResultsArea();
|
||||
}
|
||||
|
||||
void Interface::resetResultsArea()
|
||||
{
|
||||
m_resultsView->hide();
|
||||
setMinimumSize(QSize(MIN_WIDTH, m_searchTerm->sizeHint().height()));
|
||||
resize(qMax(minimumSizeHint().width(), m_defaultSize.width()), minimumSizeHint().height());
|
||||
}
|
||||
|
||||
#include "moc_interface.cpp"
|
|
@ -1,124 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2006 by Aaron Seigo <aseigo@kde.org> *
|
||||
* Copyright 2008 by Davide Bettio <davide.bettio@kdemail.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; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef INTERFACE_H
|
||||
#define INTERFACE_H
|
||||
|
||||
#include <QtCore/qmap.h>
|
||||
#include <QTimer>
|
||||
|
||||
// local includes
|
||||
#include "krunnerdialog.h"
|
||||
#include "resultitem.h"
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsItem>
|
||||
#include <QLabel>
|
||||
#include <QToolButton>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
class KCompletion;
|
||||
class KrunnerHistoryComboBox;
|
||||
class KLineEdit;
|
||||
|
||||
class ResultItem;
|
||||
class ResultScene;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class RunnerManager;
|
||||
class Svg;
|
||||
}
|
||||
|
||||
class Interface : public KRunnerDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Interface(Plasma::RunnerManager *m_runnerManager, QWidget* parent = 0);
|
||||
~Interface();
|
||||
|
||||
void setConfigWidget(QWidget *w);
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
public Q_SLOTS:
|
||||
void display(const QString& term = QString());
|
||||
void clearHistory();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *);
|
||||
void hideEvent(QHideEvent *e);
|
||||
|
||||
private slots:
|
||||
void fitWindow();
|
||||
void reenableHoverEvents();
|
||||
void run(ResultItem *item);
|
||||
void runDefaultResultItem();
|
||||
void queryTextEdited(const QString &query);
|
||||
void matchCountChanged(int count);
|
||||
void hideResultsArea();
|
||||
void themeUpdated();
|
||||
void resetInterface();
|
||||
void showHelp();
|
||||
void cleanupAfterConfigWidget();
|
||||
void configWidgetDestroyed();
|
||||
void searchTermSetFocus();
|
||||
void resetAndClose();
|
||||
void delayedQueryLaunch();
|
||||
void updateSystemActivityToolTip();
|
||||
void saveCurrentDialogSize();
|
||||
|
||||
private:
|
||||
void saveDialogSize(KConfigGroup &group);
|
||||
void restoreDialogSize(KConfigGroup &group);
|
||||
void centerOnScreen();
|
||||
void setStaticQueryMode(bool staticQuery);
|
||||
void resetResultsArea();
|
||||
|
||||
QTimer m_hideResultsTimer;
|
||||
QTimer m_reenableHoverEventsTimer;
|
||||
QTimer m_saveDialogSizeTimer;
|
||||
|
||||
QWidget *m_buttonContainer;
|
||||
QVBoxLayout* m_layout;
|
||||
QLabel *m_previousPage;
|
||||
QLabel *m_nextPage;
|
||||
QToolButton *m_configButton;
|
||||
QToolButton *m_activityButton;
|
||||
QToolButton *m_helpButton;
|
||||
QToolButton *m_closeButton;
|
||||
KrunnerHistoryComboBox* m_searchTerm;
|
||||
KCompletion *m_completion;
|
||||
QGraphicsView *m_resultsView;
|
||||
ResultScene *m_resultsScene;
|
||||
int m_minimumHeight;
|
||||
QSize m_defaultSize;
|
||||
QLabel *m_singleRunnerIcon;
|
||||
QLabel *m_singleRunnerDisplayName;
|
||||
KLineEdit *m_singleRunnerSearchTerm;
|
||||
QTimer m_delayedQueryTimer;
|
||||
SharedResultData m_resultData;
|
||||
bool m_delayedRun : 1;
|
||||
bool m_running : 1;
|
||||
bool m_queryRunning : 1;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,130 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2009 by Jacopo De Simoi <wilderkde@gmail.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 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; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#include "krunnerhistorycombobox.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTimer>
|
||||
|
||||
#include <KDebug>
|
||||
#include <KLineEdit>
|
||||
#include <KStandardShortcut>
|
||||
|
||||
KrunnerHistoryComboBox::KrunnerHistoryComboBox(bool useCompletion, QWidget * parent)
|
||||
: KHistoryComboBox(useCompletion, parent),
|
||||
m_addingToHistory(false)
|
||||
{
|
||||
setPalette(QApplication::palette());
|
||||
setDuplicatesEnabled(false);
|
||||
setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
|
||||
|
||||
// in theory, the widget should detect the direction from the content
|
||||
// but this is not available in Qt4.4/KDE 4.2, so the best default for this widget
|
||||
// is LTR: as it's more or less a "command line interface"
|
||||
// FIXME remove this code when KLineEdit has automatic direction detection of the "paragraph"
|
||||
setLayoutDirection(Qt::LeftToRight);
|
||||
}
|
||||
|
||||
KrunnerHistoryComboBox::~KrunnerHistoryComboBox()
|
||||
{
|
||||
}
|
||||
|
||||
void KrunnerHistoryComboBox::addToHistory(const QString & item)
|
||||
{
|
||||
m_addingToHistory = true;
|
||||
KHistoryComboBox::addToHistory(item);
|
||||
m_addingToHistory = false;
|
||||
}
|
||||
|
||||
void KrunnerHistoryComboBox::setLineEdit(QLineEdit *e)
|
||||
{
|
||||
if (lineEdit()) {
|
||||
disconnect(lineEdit(), 0, this, 0);
|
||||
}
|
||||
|
||||
KComboBox::setLineEdit(e);
|
||||
QTimer::singleShot(50, this, SLOT(connectLineEdit()));
|
||||
}
|
||||
|
||||
void KrunnerHistoryComboBox::connectLineEdit()
|
||||
{
|
||||
disconnect(this, SIGNAL(currentIndexChanged(QString)), this, SLOT(currentIndexChanged(QString)));
|
||||
connect(this, SIGNAL(currentIndexChanged(QString)), this, SLOT(currentIndexChanged(QString)));
|
||||
|
||||
if (lineEdit()) {
|
||||
disconnect(lineEdit(), SIGNAL(textEdited(QString)), this, SIGNAL(queryTextEdited(QString)));
|
||||
connect(lineEdit(), SIGNAL(textEdited(QString)), this, SIGNAL(queryTextEdited(QString)));
|
||||
}
|
||||
}
|
||||
|
||||
void KrunnerHistoryComboBox::focusOutEvent(QFocusEvent *e)
|
||||
{
|
||||
discardCompletion();
|
||||
KHistoryComboBox::focusOutEvent(e);
|
||||
}
|
||||
|
||||
void KrunnerHistoryComboBox::wheelEvent(QWheelEvent *e)
|
||||
{
|
||||
KHistoryComboBox::wheelEvent(e);
|
||||
emit queryTextEdited(lineEdit()->text());
|
||||
}
|
||||
|
||||
void KrunnerHistoryComboBox::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
|
||||
discardCompletion();
|
||||
emit returnPressed();
|
||||
} else {
|
||||
KHistoryComboBox::keyPressEvent(e);
|
||||
}
|
||||
|
||||
int event_key = e->key() | e->modifiers();
|
||||
if (KStandardShortcut::rotateUp().contains(event_key) ||
|
||||
KStandardShortcut::rotateDown().contains(event_key)) {
|
||||
emit queryTextEdited(lineEdit()->text());
|
||||
}
|
||||
}
|
||||
|
||||
void KrunnerHistoryComboBox::discardCompletion()
|
||||
{
|
||||
//FIXME: find a reliable way to see if the scene is empty; now defaults to
|
||||
// never complete
|
||||
bool emptyScene = false;
|
||||
KLineEdit* edit = static_cast<KLineEdit*>(lineEdit());
|
||||
bool suggestedCompletion = (edit->text() != edit->userText());
|
||||
|
||||
if (emptyScene && suggestedCompletion) {
|
||||
// We hit TAB with an empty scene and a suggested completion:
|
||||
// Complete but don't lose focus
|
||||
edit->setText(edit->text());
|
||||
} else if (suggestedCompletion) {
|
||||
// We hit TAB with a non-empty scene and a suggested completion:
|
||||
// Assume the user wants to switch input to the results scene and discard the completion
|
||||
edit->setText(edit->userText());
|
||||
}
|
||||
}
|
||||
|
||||
void KrunnerHistoryComboBox::currentIndexChanged(const QString &item)
|
||||
{
|
||||
if (!m_addingToHistory) {
|
||||
emit queryTextEdited(item);
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_krunnerhistorycombobox.cpp"
|
|
@ -1,63 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2009 by Jacopo De Simoi <wilderkde@gmail.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 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; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef KRUNNERHISTORYCOMBOBOX_H
|
||||
#define KRUNNERHISTORYCOMBOBOX_H
|
||||
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QtGui/qevent.h>
|
||||
|
||||
#include <KHistoryComboBox>
|
||||
|
||||
class KrunnerHistoryComboBox : public KHistoryComboBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit KrunnerHistoryComboBox(bool useCompletion, QWidget *parent = 0);
|
||||
~KrunnerHistoryComboBox();
|
||||
void setLineEdit(QLineEdit* edit);
|
||||
|
||||
public slots:
|
||||
void addToHistory(const QString& item);
|
||||
|
||||
signals:
|
||||
void queryTextEdited(QString);
|
||||
|
||||
protected:
|
||||
virtual void keyPressEvent(QKeyEvent *);
|
||||
virtual void focusOutEvent(QFocusEvent *);
|
||||
virtual void wheelEvent(QWheelEvent *);
|
||||
|
||||
private:
|
||||
void discardCompletion();
|
||||
|
||||
private slots:
|
||||
void currentIndexChanged(const QString &);
|
||||
void connectLineEdit();
|
||||
|
||||
private:
|
||||
bool m_addingToHistory;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,654 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2007 by Enrico Ros <enrico.ros@gmail.com> *
|
||||
* Copyright 2007 by Riccardo Iaconelli <ruphy@kde.org> *
|
||||
* Copyright 2008 by Davide Bettio <davide.bettio@kdemail.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; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "resultitem.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsItemAnimation>
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QGraphicsScene>
|
||||
#include <QtGui/qgraphicssceneevent.h>
|
||||
#include <QGraphicsView>
|
||||
#include <QPainter>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QtGui/qstyleoption.h>
|
||||
#include <QTimeLine>
|
||||
#include <QTimer>
|
||||
|
||||
#include <KDebug>
|
||||
#include <KGlobalSettings>
|
||||
#include <KIcon>
|
||||
#include <KIconLoader>
|
||||
|
||||
#include <Plasma/PaintUtils>
|
||||
#include <Plasma/ToolButton>
|
||||
#include <Plasma/Plasma>
|
||||
#include <Plasma/RunnerManager>
|
||||
|
||||
//#define NO_GROW_ANIM
|
||||
|
||||
ResultItem::ResultItem(const SharedResultData *sharedData, QGraphicsWidget *parent)
|
||||
: QGraphicsWidget(parent),
|
||||
m_match(0),
|
||||
m_configButton(0),
|
||||
m_highlight(0),
|
||||
m_index(-1),
|
||||
m_configWidget(0),
|
||||
m_actionsWidget(0),
|
||||
m_actionsLayout(0),
|
||||
m_sharedData(sharedData),
|
||||
m_mouseHovered(false),
|
||||
m_mimeDataFailed(false)
|
||||
{
|
||||
m_highlightCheckTimer.setInterval(0);
|
||||
m_highlightCheckTimer.setSingleShot(true);
|
||||
connect(&m_highlightCheckTimer, SIGNAL(timeout()), this, SLOT(checkHighlighting()));
|
||||
setFlag(QGraphicsItem::ItemIsFocusable);
|
||||
setFlag(QGraphicsItem::ItemIsSelectable);
|
||||
setAcceptHoverEvents(true);
|
||||
setFocusPolicy(Qt::TabFocus);
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
setZValue(0);
|
||||
|
||||
m_highlightAnim = new QPropertyAnimation(this, "highlightState", this);
|
||||
m_highlightAnim->setStartValue(0);
|
||||
m_highlightAnim->setEndValue(1);
|
||||
m_highlightAnim->setDuration(50);
|
||||
m_highlightAnim->setEasingCurve(QEasingCurve::OutCubic);
|
||||
}
|
||||
|
||||
ResultItem::~ResultItem()
|
||||
{
|
||||
}
|
||||
|
||||
QGraphicsWidget *ResultItem::firstTabItem()
|
||||
{
|
||||
if (m_configButton) {
|
||||
return m_configButton;
|
||||
}
|
||||
|
||||
if (m_actionsWidget) {
|
||||
return m_actionsWidget;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
QGraphicsWidget *ResultItem::arrangeTabOrder(QGraphicsWidget* last)
|
||||
{
|
||||
QGraphicsWidget *sceneWidget = static_cast<QGraphicsWidget*>(parent());
|
||||
sceneWidget->setTabOrder(last, this);
|
||||
QGraphicsWidget *currentWidget = this;
|
||||
|
||||
if (m_configButton) {
|
||||
sceneWidget->setTabOrder(this, m_configButton);
|
||||
currentWidget = m_configButton;
|
||||
if (m_configWidget) {
|
||||
sceneWidget->setTabOrder(m_configButton, m_configWidget);
|
||||
currentWidget = m_configWidget;
|
||||
}
|
||||
}
|
||||
if (m_actionsWidget) {
|
||||
for (int i = 0; i < m_actionsLayout->count(); ++i) {
|
||||
QGraphicsWidget *button = static_cast<QGraphicsWidget*>(m_actionsLayout->itemAt(i));
|
||||
sceneWidget->setTabOrder(currentWidget, button);
|
||||
currentWidget = button;
|
||||
}
|
||||
}
|
||||
|
||||
return currentWidget;
|
||||
}
|
||||
|
||||
bool ResultItem::isValid() const
|
||||
{
|
||||
return m_match.isValid() || m_match.type() == Plasma::QueryMatch::InformationalMatch;
|
||||
}
|
||||
|
||||
void ResultItem::setMatch(const Plasma::QueryMatch &match)
|
||||
{
|
||||
m_mimeDataFailed = false;
|
||||
m_match = match;
|
||||
m_icon = KIcon(match.icon());
|
||||
|
||||
if (m_configWidget) {
|
||||
if (scene()) {
|
||||
scene()->removeItem(m_configWidget);
|
||||
}
|
||||
|
||||
delete m_configWidget;
|
||||
m_configWidget = 0;
|
||||
}
|
||||
|
||||
if (m_actionsWidget) {
|
||||
if (scene()) {
|
||||
scene()->removeItem(m_actionsWidget);
|
||||
}
|
||||
|
||||
delete m_actionsWidget;
|
||||
m_actionsWidget = 0;
|
||||
}
|
||||
|
||||
//kDebug() << match.hasConfigurationInterface();
|
||||
if (match.hasConfigurationInterface()) {
|
||||
if (!m_configButton) {
|
||||
m_configButton = new Plasma::ToolButton(this);
|
||||
m_configButton->setIcon(KIcon(QLatin1String( "configure" )));
|
||||
m_configButton->show();
|
||||
m_configButton->resize(m_configButton->effectiveSizeHint(Qt::MinimumSize,
|
||||
QSize(KIconLoader::SizeSmall,
|
||||
KIconLoader::SizeSmall)));
|
||||
connect(m_configButton, SIGNAL(clicked()), this, SLOT(showConfig()));
|
||||
m_configButton->installEventFilter(this);
|
||||
}
|
||||
} else if (m_configButton) {
|
||||
if (scene()) {
|
||||
scene()->removeItem(m_configButton);
|
||||
}
|
||||
|
||||
delete m_configButton;
|
||||
m_configButton = 0;
|
||||
}
|
||||
|
||||
setupActions();
|
||||
calculateSize();
|
||||
|
||||
if (!m_match.isValid() && isSelected() && scene()) {
|
||||
scene()->clearSelection();
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void ResultItem::setupActions()
|
||||
{
|
||||
//kDebug();
|
||||
QList<QAction*> actionList = m_sharedData->runnerManager->actionsForMatch(m_match);
|
||||
|
||||
if (!actionList.isEmpty()) {
|
||||
m_actionsWidget = new QGraphicsWidget(this);
|
||||
m_actionsLayout = new QGraphicsLinearLayout(Qt::Horizontal, m_actionsWidget);
|
||||
m_actionsLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_actionsLayout->setSpacing(0);
|
||||
|
||||
foreach (QAction* action, actionList) {
|
||||
Plasma::ToolButton * actionButton = new Plasma::ToolButton(m_actionsWidget);
|
||||
actionButton->setFlag(QGraphicsItem::ItemIsFocusable);
|
||||
actionButton->setAction(action);
|
||||
actionButton->show();
|
||||
actionButton->resize(actionButton->effectiveSizeHint(Qt::MinimumSize,
|
||||
QSize(KIconLoader::SizeSmall,
|
||||
KIconLoader::SizeSmall)));
|
||||
m_actionsLayout->addItem(actionButton);
|
||||
connect(actionButton, SIGNAL(clicked()), this , SLOT(actionClicked()));
|
||||
actionButton->installEventFilter(this);
|
||||
}
|
||||
m_actionsWidget->show();
|
||||
}
|
||||
}
|
||||
|
||||
void ResultItem::actionClicked()
|
||||
{
|
||||
Plasma::ToolButton * actionButton = static_cast<Plasma::ToolButton*>(sender());
|
||||
m_match.setSelectedAction(actionButton->action());
|
||||
emit activated(this);
|
||||
}
|
||||
|
||||
bool ResultItem::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
Plasma::ToolButton* actionButton = static_cast<Plasma::ToolButton*>(obj);
|
||||
|
||||
if (actionButton) {
|
||||
if (event->type() == QEvent::GraphicsSceneHoverEnter) {
|
||||
if (scene()) {
|
||||
scene()->setFocusItem(actionButton);
|
||||
}
|
||||
} else if (event->type() == QEvent::FocusIn) {
|
||||
focusInEvent(static_cast<QFocusEvent*>(event));
|
||||
actionButton->setAutoRaise(false);
|
||||
} else if (event->type() == QEvent::GraphicsSceneHoverLeave || event->type() == QEvent::FocusOut) {
|
||||
actionButton->setAutoRaise(true);
|
||||
} else if (event->type() == QEvent::KeyPress) {
|
||||
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
||||
if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) {
|
||||
if (actionButton->action()) {
|
||||
m_match.setSelectedAction(actionButton->action());
|
||||
emit activated(this);
|
||||
} else {
|
||||
showConfig();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QString ResultItem::id() const
|
||||
{
|
||||
return m_match.id();
|
||||
}
|
||||
|
||||
bool ResultItem::compare(const ResultItem *one, const ResultItem *other)
|
||||
{
|
||||
return other->m_match < one->m_match;
|
||||
}
|
||||
|
||||
bool ResultItem::operator<(const ResultItem &other) const
|
||||
{
|
||||
return m_match < other.m_match;
|
||||
}
|
||||
|
||||
QString ResultItem::name() const
|
||||
{
|
||||
return m_match.text();
|
||||
}
|
||||
|
||||
QString ResultItem::description() const
|
||||
{
|
||||
if (!scene()) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
Plasma::ToolButton* actionButton = qobject_cast<Plasma::ToolButton*>(static_cast<QGraphicsWidget*>(scene()->focusItem()));
|
||||
|
||||
//if a button is focused and it belongs to the item
|
||||
if (actionButton && actionButton->parentWidget() == m_actionsWidget) {
|
||||
return actionButton->text();
|
||||
}
|
||||
|
||||
return m_match.subtext();
|
||||
}
|
||||
|
||||
QString ResultItem::data() const
|
||||
{
|
||||
return m_match.data().toString();
|
||||
}
|
||||
|
||||
QIcon ResultItem::icon() const
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
Plasma::QueryMatch::Type ResultItem::group() const
|
||||
{
|
||||
return m_match.type();
|
||||
}
|
||||
|
||||
bool ResultItem::isQueryPrototype() const
|
||||
{
|
||||
//FIXME: pretty lame way to decide if this is a query prototype
|
||||
return m_match.runner() == 0;
|
||||
}
|
||||
|
||||
qreal ResultItem::priority() const
|
||||
{
|
||||
// TODO, need to fator in more things than just this
|
||||
return m_match.relevance();
|
||||
}
|
||||
|
||||
void ResultItem::setIndex(int index)
|
||||
{
|
||||
if (m_index == index) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_index = qMax(-1, index);
|
||||
}
|
||||
|
||||
int ResultItem::index() const
|
||||
{
|
||||
return m_index;
|
||||
}
|
||||
|
||||
void ResultItem::run(Plasma::RunnerManager *manager)
|
||||
{
|
||||
manager->run(m_match);
|
||||
}
|
||||
|
||||
void ResultItem::drawIcon(QPainter *painter, const QRect &iRect, const QPixmap &p)
|
||||
{
|
||||
//QPixmap p = m_icon.pixmap(iconSize, QIcon::Active);
|
||||
QRect r = p.rect();
|
||||
r.moveCenter(iRect.center());
|
||||
painter->drawPixmap(r, p);
|
||||
}
|
||||
|
||||
void ResultItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
|
||||
if (!m_match.isValid() && m_match.type() != Plasma::QueryMatch::InformationalMatch) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool oldClipping = painter->hasClipping();
|
||||
painter->setClipping(false);
|
||||
|
||||
QSize iconSize(KIconLoader::SizeMedium, KIconLoader::SizeMedium);
|
||||
QRect iRect = QStyle::alignedRect(option->direction, Qt::AlignLeft, iconSize, contentsRect().toRect());
|
||||
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
if (qFuzzyCompare(m_highlight + 1, 1)) {
|
||||
drawIcon(painter, iRect, m_icon.pixmap(iconSize, QIcon::Disabled));
|
||||
} else if (qFuzzyCompare(m_highlight, qreal(1.0))) {
|
||||
drawIcon(painter, iRect, m_icon.pixmap(iconSize, QIcon::Active));
|
||||
} else {
|
||||
painter->setOpacity(painter->opacity() * (1 - m_highlight));
|
||||
drawIcon(painter, iRect, m_icon.pixmap(iconSize, QIcon::Disabled));
|
||||
painter->setOpacity(m_highlight);
|
||||
drawIcon(painter, iRect, m_icon.pixmap(iconSize, QIcon::Active));
|
||||
painter->setOpacity(1);
|
||||
}
|
||||
|
||||
QRect textRect(iRect.topLeft() + QPoint(iconSize.width() + TEXT_MARGIN, 0),
|
||||
contentsRect().size().toSize() - QSize(iRect.width(), 0));
|
||||
if (option->direction == Qt::RightToLeft) {
|
||||
textRect.moveRight(iRect.left() - TEXT_MARGIN);
|
||||
}
|
||||
|
||||
// Draw the text on a pixmap
|
||||
const QColor textColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
|
||||
const int width = option->fontMetrics.width(name());
|
||||
QPixmap pixmap(textRect.size());
|
||||
pixmap.fill(Qt::transparent);
|
||||
|
||||
QPainter p(&pixmap);
|
||||
p.setPen(textColor);
|
||||
//TODO: add subtext, make bold, etc...
|
||||
p.drawText(pixmap.rect(), Qt::AlignLeft | Qt::TextWordWrap, name());
|
||||
QFont italics = p.font();
|
||||
QFontMetrics italicMetrics(italics);
|
||||
int fontHeight = italicMetrics.boundingRect(pixmap.rect(), Qt::AlignLeft | Qt::TextWordWrap, name()).height();
|
||||
italics.setItalic(true);
|
||||
p.setFont(italics);
|
||||
p.drawText(pixmap.rect().adjusted(0, fontHeight, 0, 0), Qt::AlignLeft | Qt::TextWordWrap, description());
|
||||
|
||||
// Fade the pixmap out at the end
|
||||
if (width > pixmap.width()) {
|
||||
if (m_fadeout.isNull() || m_fadeout.height() != pixmap.height()) {
|
||||
QLinearGradient g(0, 0, 20, 0);
|
||||
g.setColorAt(0, layoutDirection() == Qt::LeftToRight ? Qt::white : Qt::transparent);
|
||||
g.setColorAt(1, layoutDirection() == Qt::LeftToRight ? Qt::transparent : Qt::white);
|
||||
m_fadeout = QPixmap(20, textRect.height());
|
||||
m_fadeout.fill(Qt::transparent);
|
||||
QPainter p(&m_fadeout);
|
||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
p.fillRect(m_fadeout.rect(), g);
|
||||
}
|
||||
const QRect r = QStyle::alignedRect(layoutDirection(), Qt::AlignRight, m_fadeout.size(), pixmap.rect());
|
||||
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
p.drawPixmap(r.topLeft(), m_fadeout);
|
||||
}
|
||||
p.end();
|
||||
|
||||
// Draw a drop shadow if we have a bright text color
|
||||
if (qGray(textColor.rgb()) > 192) {
|
||||
const int blur = 2;
|
||||
const QPoint offset(1, 1);
|
||||
|
||||
QImage shadow(pixmap.size() + QSize(blur * 2, blur * 2), QImage::Format_ARGB32_Premultiplied);
|
||||
p.begin(&shadow);
|
||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
p.fillRect(shadow.rect(), Qt::transparent);
|
||||
p.drawPixmap(blur, blur, pixmap);
|
||||
p.end();
|
||||
|
||||
Plasma::PaintUtils::shadowBlur(shadow, blur, Qt::black);
|
||||
|
||||
// Draw the shadow
|
||||
painter->drawImage(textRect.topLeft() - QPoint(blur, blur) + offset, shadow);
|
||||
}
|
||||
|
||||
// Draw the text
|
||||
painter->drawPixmap(textRect.topLeft(), pixmap);
|
||||
painter->setClipping(oldClipping);
|
||||
}
|
||||
|
||||
void ResultItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
|
||||
{
|
||||
//kDebug() << "in on" << m_match.text() << m_sharedData->processHoverEvents;
|
||||
if (!m_sharedData->processHoverEvents || !m_match.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QGraphicsItem::hoverEnterEvent(e);
|
||||
setFocus(Qt::MouseFocusReason);
|
||||
}
|
||||
|
||||
void ResultItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (geometry().contains(event->scenePos())) {
|
||||
emit activated(this);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (!m_mimeDataFailed &&
|
||||
event->buttons() == Qt::LeftButton &&
|
||||
(event->pos() - event->buttonDownPos(Qt::LeftButton)).manhattanLength() >= KGlobalSettings::dndEventDelay()) {
|
||||
QMimeData *mime = m_sharedData->runnerManager->mimeDataForMatch(m_match);
|
||||
//kDebug() << mime << m_match.text() << m_match.id() << m_match.data();
|
||||
if (mime) {
|
||||
QDrag *drag = new QDrag(event->widget());
|
||||
drag->setMimeData(mime);
|
||||
drag->exec();
|
||||
}
|
||||
|
||||
m_mimeDataFailed = !mime;
|
||||
}
|
||||
}
|
||||
|
||||
bool ResultItem::mouseHovered() const
|
||||
{
|
||||
return m_mouseHovered;
|
||||
}
|
||||
|
||||
void ResultItem::focusInEvent(QFocusEvent * event)
|
||||
{
|
||||
QGraphicsWidget::focusInEvent(event);
|
||||
//kDebug() << hasFocus();
|
||||
setZValue(1);
|
||||
|
||||
m_mouseHovered = (event->reason() == Qt::MouseFocusReason);
|
||||
|
||||
if (scene()) {
|
||||
scene()->clearSelection();
|
||||
}
|
||||
|
||||
setSelected(true);
|
||||
emit ensureVisibility(this);
|
||||
}
|
||||
|
||||
void ResultItem::highlight(bool yes)
|
||||
{
|
||||
if (yes) {
|
||||
if (m_highlight < 1) {
|
||||
m_highlightAnim->setDirection(QAbstractAnimation::Forward);
|
||||
m_highlightAnim->start();
|
||||
}
|
||||
} else if (m_highlight > 0) {
|
||||
m_highlightAnim->setDirection(QAbstractAnimation::Backward);
|
||||
m_highlightAnim->start();
|
||||
}
|
||||
}
|
||||
|
||||
qreal ResultItem::highlightState() const
|
||||
{
|
||||
return m_highlight;
|
||||
}
|
||||
|
||||
void ResultItem::setHighlightState(qreal highlight)
|
||||
{
|
||||
m_highlight = highlight;
|
||||
update();
|
||||
}
|
||||
|
||||
void ResultItem::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
|
||||
emit activated(this);
|
||||
} else {
|
||||
event->ignore();
|
||||
QGraphicsWidget::keyPressEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
QVariant ResultItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == QGraphicsItem::ItemSceneHasChanged) {
|
||||
calculateSize();
|
||||
} else if (change == QGraphicsItem::ItemSelectedHasChanged && !isSelected()) {
|
||||
m_highlightCheckTimer.start();
|
||||
}
|
||||
|
||||
return QGraphicsWidget::itemChange(change, value);
|
||||
}
|
||||
|
||||
void ResultItem::checkHighlighting()
|
||||
{
|
||||
highlight(isSelected());
|
||||
}
|
||||
|
||||
void ResultItem::resizeEvent(QGraphicsSceneResizeEvent *)
|
||||
{
|
||||
emit sizeChanged(this);
|
||||
}
|
||||
|
||||
void ResultItem::changeEvent(QEvent *event)
|
||||
{
|
||||
QGraphicsWidget::changeEvent(event);
|
||||
|
||||
if (event->type() == QEvent::ContentsRectChange) {
|
||||
calculateSize();
|
||||
}
|
||||
}
|
||||
|
||||
void ResultItem::showConfig()
|
||||
{
|
||||
if (m_configWidget) {
|
||||
if (scene()) {
|
||||
scene()->removeItem(m_configWidget);
|
||||
}
|
||||
|
||||
delete m_configWidget;
|
||||
m_configWidget = 0;
|
||||
} else {
|
||||
QWidget *w = new QWidget;
|
||||
m_match.createConfigurationInterface(w);
|
||||
w->setAttribute(Qt::WA_NoSystemBackground);
|
||||
m_configWidget = new QGraphicsProxyWidget(this);
|
||||
m_configWidget->setWidget(w);
|
||||
m_configWidget->show();
|
||||
QGraphicsWidget* sceneWidget = parentWidget();
|
||||
sceneWidget->setTabOrder(m_configButton, m_configWidget);
|
||||
}
|
||||
|
||||
calculateSize();
|
||||
update();
|
||||
}
|
||||
|
||||
void ResultItem::calculateSize()
|
||||
{
|
||||
if (scene()) {
|
||||
calculateSize(scene()->width());
|
||||
}
|
||||
}
|
||||
|
||||
void ResultItem::calculateSize(int sceneWidth)
|
||||
{
|
||||
QRect textBounds(contentsRect().toRect());
|
||||
|
||||
textBounds.setWidth(sceneWidth);
|
||||
|
||||
QString text = name();
|
||||
|
||||
if (!description().isEmpty()) {
|
||||
text.append(QLatin1Char( '\n' )).append(description());
|
||||
}
|
||||
|
||||
const QFontMetrics fm(font());
|
||||
const int maxHeight = fm.height() * 4;
|
||||
const int minHeight = KIconLoader::SizeMedium;
|
||||
|
||||
textBounds.adjust(minHeight + TEXT_MARGIN, 0, 0, 0);
|
||||
|
||||
if (maxHeight > textBounds.height()) {
|
||||
textBounds.setHeight(maxHeight);
|
||||
}
|
||||
|
||||
int height = fm.boundingRect(textBounds, Qt::AlignLeft | Qt::TextWordWrap, text).height();
|
||||
//kDebug() << (QObject*)this << text << fm.boundingRect(textBounds, Qt::AlignLeft | Qt::TextWordWrap, text);
|
||||
//kDebug() << fm.height() << maxHeight << textBounds << height << minHeight << qMax(height, minHeight);
|
||||
int innerHeight = qMax(height, minHeight);
|
||||
|
||||
qreal left, top, right, bottom;
|
||||
getContentsMargins(&left, &top, &right, &bottom);
|
||||
QSize newSize(sceneWidth, innerHeight + top + bottom);
|
||||
//kDebug() << innerHeight << geometry().size();
|
||||
|
||||
if (m_configWidget) {
|
||||
m_configWidget->setMaximumWidth(newSize.width());
|
||||
m_configWidget->adjustSize();
|
||||
const QSizeF s = m_configWidget->size();
|
||||
newSize.setHeight(newSize.height() + s.height());
|
||||
m_configWidget->setPos((newSize.width() - s.width()) / 2,
|
||||
newSize.height() - s.height() - bottom);
|
||||
}
|
||||
|
||||
if (m_configButton) {
|
||||
const QSizeF s = m_configButton->size();
|
||||
|
||||
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
||||
m_configButton->setPos(left, newSize.height() - s.height() - bottom);
|
||||
left += s.width();
|
||||
} else {
|
||||
m_configButton->setPos(newSize.width() - s.width() - right,
|
||||
newSize.height() - s.height() - bottom);
|
||||
right += s.width();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_actionsWidget) {
|
||||
m_actionsWidget->setMaximumWidth(newSize.width()/2);
|
||||
m_actionsWidget->adjustSize();
|
||||
const QSizeF s = m_actionsWidget->size();
|
||||
|
||||
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
||||
m_actionsWidget->setPos(left, newSize.height() - s.height() - bottom);
|
||||
} else {
|
||||
m_actionsWidget->setPos(newSize.width() - s.width() - right,
|
||||
newSize.height() - s.height() - bottom);
|
||||
}
|
||||
}
|
||||
|
||||
resize(newSize);
|
||||
}
|
||||
|
||||
#include "moc_resultitem.cpp"
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2007 by Enrico Ros <enrico.ros@gmail.com> *
|
||||
* Copyright 2007 by Riccardo Iaconelli <ruphy@kde.org> *
|
||||
* Copyright 2008 by Davide Bettio <davide.bettio@kdemail.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; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef __ResultItem_h__
|
||||
#define __ResultItem_h__
|
||||
|
||||
#include <QGraphicsWidget>
|
||||
#include <QIcon>
|
||||
#include <QTimer>
|
||||
|
||||
#include <Plasma/QueryMatch>
|
||||
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QGraphicsProxyWidget>
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class ToolButton;
|
||||
class RunnerManager;
|
||||
} // namespace Plasma
|
||||
|
||||
class SharedResultData
|
||||
{
|
||||
public:
|
||||
bool processHoverEvents;
|
||||
bool mouseHovering;
|
||||
Plasma::RunnerManager *runnerManager;
|
||||
};
|
||||
|
||||
class ResultItemSignaller : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ResultItemSignaller(QObject *parent = 0)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void startAnimations()
|
||||
{
|
||||
emit animate();
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
void animate();
|
||||
};
|
||||
|
||||
class ResultItem : public QGraphicsWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(qreal highlightState READ highlightState WRITE setHighlightState)
|
||||
|
||||
public:
|
||||
ResultItem(const SharedResultData *sharedData, QGraphicsWidget *parent);
|
||||
~ResultItem();
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
void setMatch(const Plasma::QueryMatch &match);
|
||||
|
||||
// getters
|
||||
bool isValid() const;
|
||||
QString id() const;
|
||||
QString name() const;
|
||||
QString description() const;
|
||||
QString data() const;
|
||||
QIcon icon() const;
|
||||
Plasma::QueryMatch::Type group() const;
|
||||
qreal priority() const;
|
||||
bool isFavorite() const;
|
||||
void setIndex(int index);
|
||||
int index() const;
|
||||
void setRowStride(int stride);
|
||||
void run(Plasma::RunnerManager *manager);
|
||||
bool isQueryPrototype() const;
|
||||
bool mouseHovered() const;
|
||||
void calculateSize();
|
||||
void calculateSize(int sceneWidth);
|
||||
QGraphicsWidget *firstTabItem();
|
||||
QGraphicsWidget* arrangeTabOrder(QGraphicsWidget* last);
|
||||
|
||||
void highlight(bool yes);
|
||||
qreal highlightState() const;
|
||||
void setHighlightState(qreal highlight);
|
||||
|
||||
static bool compare(const ResultItem *one, const ResultItem *other);
|
||||
bool operator<(const ResultItem &other) const;
|
||||
|
||||
static const int TEXT_MARGIN = 3;
|
||||
static const int TIMER_INTERVAL = 40;
|
||||
|
||||
signals:
|
||||
void indexReleased(int index);
|
||||
void activated(ResultItem *item);
|
||||
void sizeChanged(ResultItem *item);
|
||||
void ensureVisibility(QGraphicsItem *item);
|
||||
|
||||
protected:
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *e);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
||||
void focusInEvent(QFocusEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
void changeEvent(QEvent *event);
|
||||
void resizeEvent(QGraphicsSceneResizeEvent *);
|
||||
void drawIcon(QPainter *painter, const QRect &iRect, const QPixmap &p);
|
||||
void setupActions();
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
protected slots:
|
||||
void showConfig();
|
||||
|
||||
private slots:
|
||||
void actionClicked();
|
||||
void checkHighlighting();
|
||||
|
||||
private:
|
||||
Plasma::QueryMatch m_match;
|
||||
Plasma::ToolButton *m_configButton;
|
||||
|
||||
QIcon m_icon;
|
||||
QPixmap m_fadeout;
|
||||
QTimer m_highlightCheckTimer;
|
||||
qreal m_highlight;
|
||||
int m_index;
|
||||
QGraphicsProxyWidget *m_configWidget;
|
||||
QGraphicsWidget *m_actionsWidget;
|
||||
QGraphicsLinearLayout *m_actionsLayout;
|
||||
QPropertyAnimation *m_highlightAnim;
|
||||
const SharedResultData *m_sharedData;
|
||||
bool m_mouseHovered : 1;
|
||||
bool m_mimeDataFailed : 1;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,422 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2007 by Enrico Ros <enrico.ros@gmail.com> *
|
||||
* Copyright 2007 by Riccardo Iaconelli <ruphy@kde.org> *
|
||||
* Copyright 2008 by Aaron Seigo <aseigo@kde.org> *
|
||||
* Copyright 2008 by Davide Bettio <davide.bettio@kdemail.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; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#include "resultscene.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QtCore/qmutex.h>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtCore/QTimeLine>
|
||||
#include <QtGui/QGraphicsGridLayout>
|
||||
#include <QtGui/QGraphicsWidget>
|
||||
#include <QtGui/QGraphicsProxyWidget>
|
||||
#include <QtCore/QCoreApplication>
|
||||
|
||||
#include <KDebug>
|
||||
#include <KIconLoader>
|
||||
#include <KLineEdit>
|
||||
|
||||
#include <Plasma/AbstractRunner>
|
||||
#include <Plasma/RunnerManager>
|
||||
|
||||
#include "selectionbar.h"
|
||||
|
||||
ResultScene::ResultScene(SharedResultData *resultData, Plasma::RunnerManager *manager, QWidget *focusBase, QObject *parent)
|
||||
: QGraphicsScene(parent),
|
||||
m_runnerManager(manager),
|
||||
m_viewableHeight(0),
|
||||
m_currentIndex(0),
|
||||
m_focusBase(focusBase),
|
||||
m_resultData(resultData)
|
||||
{
|
||||
setItemIndexMethod(NoIndex);
|
||||
|
||||
connect(m_runnerManager, SIGNAL(matchesChanged(QList<Plasma::QueryMatch>)),
|
||||
this, SLOT(setQueryMatches(QList<Plasma::QueryMatch>)));
|
||||
|
||||
m_clearTimer.setSingleShot(true);
|
||||
m_clearTimer.setInterval(200);
|
||||
connect(&m_clearTimer, SIGNAL(timeout()), this, SLOT(clearMatches()));
|
||||
|
||||
m_arrangeTimer.setSingleShot(true);
|
||||
m_arrangeTimer.setInterval(50);
|
||||
connect(&m_arrangeTimer, SIGNAL(timeout()), this, SLOT(arrangeItems()));
|
||||
|
||||
m_selectionBar = new SelectionBar(0);
|
||||
connect(m_selectionBar, SIGNAL(appearanceChanged()), this, SLOT(updateItemMargins()));
|
||||
connect(m_selectionBar, SIGNAL(targetItemReached(QGraphicsItem*)), this, SLOT(highlightItem(QGraphicsItem*)));
|
||||
m_selectionBar->hide();
|
||||
updateItemMargins();
|
||||
|
||||
addItem(m_selectionBar);
|
||||
}
|
||||
|
||||
ResultScene::~ResultScene()
|
||||
{
|
||||
clearMatches();
|
||||
delete m_selectionBar;
|
||||
}
|
||||
|
||||
QSize ResultScene::minimumSizeHint() const
|
||||
{
|
||||
QFontMetrics fm(font());
|
||||
return QSize(KIconLoader::SizeMedium * 4, (fm.height() * 5) * 3);
|
||||
}
|
||||
|
||||
void ResultScene::setWidth(int width)
|
||||
{
|
||||
const bool resizeItems = width != sceneRect().width();
|
||||
m_selectionBar->resize(width, m_selectionBar->size().height());
|
||||
|
||||
if (resizeItems) {
|
||||
foreach (ResultItem *item, m_items) {
|
||||
item->calculateSize(width);
|
||||
}
|
||||
|
||||
setSceneRect(itemsBoundingRect());
|
||||
}
|
||||
}
|
||||
|
||||
void ResultScene::clearMatches()
|
||||
{
|
||||
clearSelection();
|
||||
Plasma::QueryMatch dummy(0);
|
||||
foreach (ResultItem *item, m_items) {
|
||||
item->hide();
|
||||
item->setMatch(dummy);
|
||||
}
|
||||
|
||||
m_viewableHeight = 0;
|
||||
emit matchCountChanged(0);
|
||||
}
|
||||
|
||||
bool ResultScene::canMoveItemFocus() const
|
||||
{
|
||||
// We prevent a late query result from stealing the item focus from the user
|
||||
// The item focus can be moved only if
|
||||
// 1) there is no item currently focused
|
||||
// 2) the currently focused item is not visible anymore
|
||||
// 3) the focusBase widget (the khistorycombobox) has focus (i.e. the user is still typing or waiting) AND the currently focused item has not been hovered
|
||||
|
||||
ResultItem * focusedItem = currentlyFocusedItem();
|
||||
|
||||
return !(focusedItem) ||
|
||||
(!m_items.contains(focusedItem)) ||
|
||||
(m_focusBase->hasFocus() && !focusedItem->mouseHovered()) ;
|
||||
}
|
||||
|
||||
int ResultScene::viewableHeight() const
|
||||
{
|
||||
return m_viewableHeight;
|
||||
}
|
||||
|
||||
void ResultScene::setQueryMatches(const QList<Plasma::QueryMatch> &m)
|
||||
{
|
||||
//kDebug() << "============================\n" << "matches retrieved: " << m.count();
|
||||
/*
|
||||
foreach (const Plasma::QueryMatch &match, m) {
|
||||
kDebug() << " " << match.id() << match.text();
|
||||
}
|
||||
*/
|
||||
|
||||
if (m.isEmpty()) {
|
||||
//kDebug() << "clearing";
|
||||
//resize(width(), 0);
|
||||
m_clearTimer.start();
|
||||
return;
|
||||
}
|
||||
|
||||
m_clearTimer.stop();
|
||||
const int maxItemsAllowed = 50;
|
||||
|
||||
if (m_items.isEmpty()) {
|
||||
//QTime t;
|
||||
//t.start();
|
||||
for (int i = 0; i < maxItemsAllowed; ++i) {
|
||||
ResultItem *item = new ResultItem(m_resultData, 0);
|
||||
item->setContentsMargins(m_itemMarginLeft, m_itemMarginTop,
|
||||
m_itemMarginRight, m_itemMarginBottom);
|
||||
item->hide();
|
||||
item->setIndex(i);
|
||||
connect(item, SIGNAL(ensureVisibility(QGraphicsItem*)), this, SIGNAL(ensureVisibility(QGraphicsItem*)));
|
||||
connect(item, SIGNAL(activated(ResultItem*)), this, SIGNAL(itemActivated(ResultItem*)));
|
||||
connect(item, SIGNAL(sizeChanged(ResultItem*)), this, SLOT(scheduleArrangeItems()));
|
||||
|
||||
m_items << item;
|
||||
addItem(item);
|
||||
}
|
||||
|
||||
arrangeItems();
|
||||
//kDebug() << "creating all items took" << t.elapsed();
|
||||
}
|
||||
|
||||
// we keep track of what was previously focused so if the user changes focus
|
||||
// and more items come in ... we don't reset that on them unecessarily
|
||||
// see the keepFocus bool down below
|
||||
ResultItem *currentFocus = currentlyFocusedItem();
|
||||
QString lastFocusId;
|
||||
if (currentFocus && currentFocus->isValid()) {
|
||||
lastFocusId = currentFocus->id();
|
||||
}
|
||||
|
||||
QList<Plasma::QueryMatch> matches = m;
|
||||
qSort(matches.begin(), matches.end());
|
||||
QListIterator<Plasma::QueryMatch> mit(matches);
|
||||
mit.toBack();
|
||||
QListIterator<ResultItem *> rit(m_items);
|
||||
QGraphicsWidget *prevTabItem = 0;
|
||||
|
||||
const int viewableHeight = m_viewableHeight;
|
||||
while (mit.hasPrevious() && rit.hasNext()) {
|
||||
ResultItem * item = rit.next();
|
||||
item->setMatch(mit.previous());
|
||||
prevTabItem = item->arrangeTabOrder(prevTabItem);
|
||||
item->show();
|
||||
m_viewableHeight = item->sceneBoundingRect().bottom();
|
||||
}
|
||||
|
||||
Plasma::QueryMatch dummy(0);
|
||||
while (rit.hasNext()) {
|
||||
ResultItem *item = rit.next();
|
||||
item->hide();
|
||||
if (item->isValid()) {
|
||||
item->setMatch(dummy);
|
||||
}
|
||||
}
|
||||
|
||||
const bool keepFocus = currentFocus && currentFocus->isValid() && currentFocus->id() == lastFocusId;
|
||||
if (keepFocus) {
|
||||
m_selectionBar->show();
|
||||
emit ensureVisibility(currentFocus);
|
||||
} else {
|
||||
clearSelection();
|
||||
ResultItem *first = m_items.at(0);
|
||||
setFocusItem(first);
|
||||
first->setSelected(true);
|
||||
first->highlight(true);
|
||||
emit ensureVisibility(first);
|
||||
}
|
||||
|
||||
emit matchCountChanged(qMin(m.count(), maxItemsAllowed));
|
||||
if (viewableHeight != m_viewableHeight) {
|
||||
emit viewableHeightChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void ResultScene::scheduleArrangeItems()
|
||||
{
|
||||
if (!m_arrangeTimer.isActive()) {
|
||||
m_arrangeTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
void ResultScene::arrangeItems()
|
||||
{
|
||||
int y = 0;
|
||||
QListIterator<ResultItem*> matchIt(m_items);
|
||||
const int viewableHeight = m_viewableHeight;
|
||||
while (matchIt.hasNext()) {
|
||||
ResultItem *item = matchIt.next();
|
||||
//kDebug() << item->name() << item->id() << item->priority() << i;
|
||||
|
||||
item->setPos(0, y);
|
||||
//kDebug() << item->pos();
|
||||
y += item->geometry().height();
|
||||
if (item->isVisible()) {
|
||||
m_viewableHeight = item->sceneBoundingRect().bottom();
|
||||
}
|
||||
}
|
||||
|
||||
//kDebug() << "setting scene rect to" << itemsBoundingRect();
|
||||
const QRectF newRect = itemsBoundingRect();
|
||||
setSceneRect(newRect);
|
||||
if (viewableHeight != m_viewableHeight) {
|
||||
emit viewableHeightChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void ResultScene::highlightItem(QGraphicsItem *item)
|
||||
{
|
||||
ResultItem *rItem = dynamic_cast<ResultItem *>(item);
|
||||
if (rItem) {
|
||||
rItem->highlight(true);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultScene::focusInEvent(QFocusEvent *focusEvent)
|
||||
{
|
||||
|
||||
// The default implementation of focusInEvent assumes that if the scene has no focus
|
||||
// then it has no focused item; thus, when a scene gains focus, focusInEvent gives
|
||||
// focus to the last focused item.
|
||||
// In our case this assumption is not true, as an item can be focused before the scene,
|
||||
// therefore we revert the behaviour by re-selecting the previously selected item
|
||||
|
||||
ResultItem *currentFocus = currentlyFocusedItem();
|
||||
|
||||
QGraphicsScene::focusInEvent(focusEvent);
|
||||
|
||||
switch (focusEvent->reason()) {
|
||||
case Qt::TabFocusReason:
|
||||
case Qt::BacktabFocusReason:
|
||||
case Qt::OtherFocusReason:
|
||||
// on tab focus in, we want to actually select the second item
|
||||
// since the first item is always "passively" selected by default
|
||||
if (!currentFocus || currentFocus == m_items.first()) {
|
||||
ResultItem *newFocus = m_items[0];
|
||||
if (newFocus->firstTabItem() != newFocus) {
|
||||
setFocusItem(newFocus->firstTabItem());
|
||||
} else {
|
||||
newFocus = m_items[1];
|
||||
if (newFocus->isVisible()) {
|
||||
setFocusItem(newFocus);
|
||||
emit ensureVisibility(newFocus);
|
||||
}
|
||||
}
|
||||
} else if (currentFocus) {
|
||||
setFocusItem(currentFocus);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (currentFocus) {
|
||||
setFocusItem(currentFocus);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ResultScene::keyPressEvent(QKeyEvent * keyEvent)
|
||||
{
|
||||
//kDebug() << "m_items (size): " << m_items.size() << "\n";
|
||||
switch (keyEvent->key()) {
|
||||
case Qt::Key_Up:
|
||||
case Qt::Key_Left:
|
||||
selectPreviousItem();
|
||||
break;
|
||||
|
||||
case Qt::Key_Down:
|
||||
case Qt::Key_Right:
|
||||
selectNextItem();
|
||||
break;
|
||||
|
||||
default:
|
||||
// pass the event to the item
|
||||
QGraphicsScene::keyPressEvent(keyEvent);
|
||||
if (!keyEvent->isAccepted() && m_focusBase &&
|
||||
(keyEvent->key() != Qt::Key_Tab) &&
|
||||
(keyEvent->key() != Qt::Key_PageUp) &&
|
||||
(keyEvent->key() != Qt::Key_PageDown) &&
|
||||
(keyEvent->modifiers() == Qt::NoModifier)) {
|
||||
m_focusBase->setFocus();
|
||||
QCoreApplication::sendEvent(m_focusBase, keyEvent);
|
||||
}
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ResultItem* ResultScene::currentlyFocusedItem() const
|
||||
{
|
||||
QGraphicsWidget* widget = static_cast<QGraphicsWidget*>(focusItem());
|
||||
if (!widget) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ResultItem *currentFocus = qobject_cast<ResultItem*>(widget);
|
||||
if (!currentFocus) {
|
||||
//If we focused an action button, find the resultItem
|
||||
//FIXME: the config button
|
||||
currentFocus = qobject_cast<ResultItem*>(widget->parentWidget()->parentWidget());
|
||||
}
|
||||
|
||||
return currentFocus;
|
||||
}
|
||||
|
||||
void ResultScene::selectPreviousItem()
|
||||
{
|
||||
ResultItem *currentFocus = currentlyFocusedItem();
|
||||
int currentIndex = currentFocus ? currentFocus->index() : 0;
|
||||
|
||||
if (currentIndex == 0) {
|
||||
m_focusBase->setFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
currentFocus = m_items.at(currentIndex - 1);
|
||||
|
||||
if (currentFocus->isVisible()) {
|
||||
setFocusItem(currentFocus);
|
||||
emit ensureVisibility(currentFocus);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultScene::selectNextItem()
|
||||
{
|
||||
ResultItem *currentFocus = currentlyFocusedItem();
|
||||
int currentIndex = currentFocus ? currentFocus->index() : 0;
|
||||
|
||||
do {
|
||||
++currentIndex;
|
||||
if (currentIndex >= m_items.size()) {
|
||||
return;
|
||||
}
|
||||
currentFocus = m_items.at(currentIndex);
|
||||
} while (!currentFocus->isVisible() && currentIndex < m_items.size());
|
||||
|
||||
if (currentFocus->isVisible()) {
|
||||
setFocusItem(currentFocus);
|
||||
emit ensureVisibility(currentFocus);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultScene::queryCleared()
|
||||
{
|
||||
//m_selectionBar->setTargetItem(0);
|
||||
setFocusItem(0);
|
||||
clearSelection();
|
||||
}
|
||||
|
||||
ResultItem* ResultScene::defaultResultItem() const
|
||||
{
|
||||
if (m_items.isEmpty()) {
|
||||
kDebug() << "empty";
|
||||
return 0;
|
||||
}
|
||||
|
||||
kDebug() << (QObject*) m_items[0] << m_items.count();
|
||||
return m_items[0];
|
||||
}
|
||||
|
||||
void ResultScene::updateItemMargins()
|
||||
{
|
||||
m_selectionBar->getContentsMargins(&m_itemMarginLeft, &m_itemMarginTop,
|
||||
&m_itemMarginRight, &m_itemMarginBottom);
|
||||
|
||||
foreach (ResultItem *item, m_items) {
|
||||
item->setContentsMargins(m_itemMarginLeft, m_itemMarginTop,
|
||||
m_itemMarginRight, m_itemMarginBottom);
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_resultscene.cpp"
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2007 by Enrico Ros <enrico.ros@gmail.com> *
|
||||
* Copyright 2007 by Riccardo Iaconelli <ruphy@kde.org> *
|
||||
* Copyright 2008 by Aaron Seigo <aseigo@kde.org> *
|
||||
* Copyright 2008 by Davide Bettio <davide.bettio@kdemail.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; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef __ResultScene_h__
|
||||
#define __ResultScene_h__
|
||||
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/qmap.h>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtGui/QGraphicsScene>
|
||||
|
||||
#include <Plasma/QueryMatch>
|
||||
|
||||
#include "resultitem.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class RunnerManager;
|
||||
}
|
||||
|
||||
class SelectionBar;
|
||||
|
||||
class ResultScene : public QGraphicsScene
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ResultScene(SharedResultData *resultData, Plasma::RunnerManager *runnerManager, QWidget *focusBase, QObject *parent = 0);
|
||||
~ResultScene();
|
||||
|
||||
void setWidth(int width);
|
||||
ResultItem* defaultResultItem() const;
|
||||
void run(ResultItem* item) const;
|
||||
QSize minimumSizeHint() const;
|
||||
int viewableHeight() const;
|
||||
|
||||
public slots:
|
||||
void setQueryMatches(const QList<Plasma::QueryMatch> &matches);
|
||||
void queryCleared();
|
||||
|
||||
signals:
|
||||
void itemActivated(ResultItem *item);
|
||||
void matchCountChanged(int count);
|
||||
void viewableHeightChanged();
|
||||
void ensureVisibility(QGraphicsItem *item);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent * keyEvent);
|
||||
void focusInEvent(QFocusEvent *focusEvent);
|
||||
|
||||
private:
|
||||
void selectPreviousItem();
|
||||
void selectNextItem();
|
||||
|
||||
ResultItem* currentlyFocusedItem() const;
|
||||
|
||||
bool canMoveItemFocus() const;
|
||||
void arrangeItems(bool setFocusAndTabbing);
|
||||
|
||||
private slots:
|
||||
void clearMatches();
|
||||
void updateItemMargins();
|
||||
void scheduleArrangeItems();
|
||||
void arrangeItems();
|
||||
void highlightItem(QGraphicsItem *item);
|
||||
|
||||
private:
|
||||
Plasma::RunnerManager *m_runnerManager;
|
||||
|
||||
QTimer m_clearTimer;
|
||||
QTimer m_arrangeTimer;
|
||||
|
||||
QList<ResultItem *> m_items;
|
||||
SelectionBar *m_selectionBar;
|
||||
|
||||
int m_viewableHeight;
|
||||
int m_currentIndex;
|
||||
qreal m_itemMarginLeft;
|
||||
qreal m_itemMarginTop;
|
||||
qreal m_itemMarginRight;
|
||||
qreal m_itemMarginBottom;
|
||||
|
||||
QWidget *m_focusBase;
|
||||
|
||||
SharedResultData *m_resultData;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,196 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2009 by Jacopo De Simoi <wilderkde@gmail.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 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; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QToolButton>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QMutex>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include <Plasma/AbstractRunner>
|
||||
#include <Plasma/Svg>
|
||||
|
||||
|
||||
#include "resultscene.h"
|
||||
#include "resultview.h"
|
||||
#include "resultitem.h"
|
||||
|
||||
ResultsView::ResultsView(ResultScene *scene, SharedResultData *resultData, QWidget *parent)
|
||||
: QGraphicsView(scene, parent),
|
||||
m_resultScene(scene),
|
||||
m_resultData(resultData)
|
||||
{
|
||||
setFrameStyle(QFrame::NoFrame);
|
||||
viewport()->setAutoFillBackground(false);
|
||||
setInteractive(true);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setOptimizationFlag(QGraphicsView::DontSavePainterState);
|
||||
setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
|
||||
m_arrowSvg = new Plasma::Svg(this);
|
||||
m_arrowSvg->setImagePath(QLatin1String( "widgets/arrows" ));
|
||||
|
||||
m_previousPage = new QToolButton(this);
|
||||
m_previousPage->setAutoRaise(true);
|
||||
m_previousPage->setVisible(false);
|
||||
connect(m_previousPage, SIGNAL(clicked(bool)), SLOT(previousPage()));
|
||||
|
||||
m_nextPage = new QToolButton(this);
|
||||
m_nextPage->setAutoRaise(true);
|
||||
m_nextPage->setVisible(false);
|
||||
connect(m_nextPage, SIGNAL(clicked(bool)), SLOT(nextPage()));
|
||||
|
||||
connect(m_arrowSvg, SIGNAL(repaintNeeded()), this, SLOT(updateArrowsIcons()));
|
||||
updateArrowsIcons();
|
||||
|
||||
connect(verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(updateArrowsVisibility()));
|
||||
connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(updateArrowsVisibility()));
|
||||
connect(m_resultScene, SIGNAL(ensureVisibility(QGraphicsItem*)), this, SLOT(ensureVisibility(QGraphicsItem*)));
|
||||
}
|
||||
|
||||
ResultsView::~ResultsView()
|
||||
{
|
||||
}
|
||||
|
||||
void ResultsView::ensureVisibility(QGraphicsItem* item)
|
||||
{
|
||||
m_resultData->processHoverEvents = false;
|
||||
ensureVisible(item, 0, 0);
|
||||
m_resultData->processHoverEvents = true;
|
||||
}
|
||||
|
||||
void ResultsView::previousPage()
|
||||
{
|
||||
QGraphicsItem *currentItem = m_resultScene->selectedItems().first();
|
||||
QGraphicsItem *item = itemAt(0, -height()*0.4);
|
||||
|
||||
if (!item) {
|
||||
item = m_resultScene->itemAt(0,0);
|
||||
}
|
||||
|
||||
if (item && (item != currentItem)) {
|
||||
m_resultScene->setFocusItem(item);
|
||||
} else {
|
||||
verticalScrollBar()->setValue(verticalScrollBar()->value()-height()*0.4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ResultsView::nextPage()
|
||||
{
|
||||
QGraphicsItem *currentItem = m_resultScene->selectedItems().first();
|
||||
QGraphicsItem *item = itemAt(0, height()*1.4);
|
||||
if (!item) {
|
||||
item = m_resultScene->itemAt(0,sceneRect().height()-1);
|
||||
}
|
||||
|
||||
ResultItem *rItem = dynamic_cast<ResultItem *>(item);
|
||||
if (rItem && !rItem->isValid()) {
|
||||
item = m_resultScene->itemAt(0, m_resultScene->viewableHeight() - 1);
|
||||
}
|
||||
|
||||
if (item && (item != currentItem)) {
|
||||
m_resultScene->setFocusItem(item);
|
||||
} else {
|
||||
verticalScrollBar()->setValue(qMin(m_resultScene->viewableHeight(),
|
||||
int(verticalScrollBar()->value()+ (height() * 0.4))));
|
||||
}
|
||||
}
|
||||
|
||||
void ResultsView::resizeEvent(QResizeEvent * event)
|
||||
{
|
||||
updateArrowsVisibility();
|
||||
QGraphicsView::resizeEvent(event);
|
||||
}
|
||||
|
||||
void ResultsView::updateArrowsIcons()
|
||||
{
|
||||
m_previousPage->setIcon(m_arrowSvg->pixmap(QLatin1String( "up-arrow" )));
|
||||
m_previousPage->adjustSize();
|
||||
|
||||
m_nextPage->setIcon(m_arrowSvg->pixmap(QLatin1String( "down-arrow" )));
|
||||
m_nextPage->adjustSize();
|
||||
|
||||
updateArrowsVisibility();
|
||||
}
|
||||
|
||||
void ResultsView::updateArrowsVisibility()
|
||||
{
|
||||
m_previousPage->move((width() / 2) - (m_previousPage->width() / 2), 0);
|
||||
m_nextPage->move((width() / 2) - (m_nextPage->width() / 2), height() - m_nextPage->height());
|
||||
|
||||
m_previousPage->setVisible(mapFromScene(QPointF(0,0)).y() < 0);
|
||||
m_nextPage->setVisible(mapFromScene(QPointF(0, m_resultScene->viewableHeight())).y() > height());
|
||||
//kDebug() << m_resultScene->viewableHeight() << height() << mapFromScene(QPointF(0, m_resultScene->viewableHeight()));
|
||||
}
|
||||
|
||||
void ResultsView::wheelEvent(QWheelEvent *e)
|
||||
{
|
||||
if (e->delta() < 0 && !m_nextPage->isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QGraphicsView::wheelEvent(e);
|
||||
}
|
||||
|
||||
void ResultsView::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QGraphicsView::paintEvent(event);
|
||||
|
||||
QPainter painter(viewport());
|
||||
|
||||
if (m_previousFadeout.isNull() || m_previousFadeout.width() != width()) {
|
||||
QLinearGradient g(0, 0, 0, m_previousPage->height());
|
||||
g.setColorAt(1, Qt::white );
|
||||
g.setColorAt(0, Qt::transparent );
|
||||
m_previousFadeout = QPixmap(width(), m_previousPage->height());
|
||||
m_previousFadeout.fill(Qt::transparent);
|
||||
QPainter p(&m_previousFadeout);
|
||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
p.fillRect(m_previousFadeout.rect(), g);
|
||||
}
|
||||
|
||||
if (m_nextFadeout.isNull() || m_nextFadeout.width() != width()) {
|
||||
QLinearGradient g(0, 0, 0, m_nextPage->height());
|
||||
g.setColorAt(0, Qt::white );
|
||||
g.setColorAt(1, Qt::transparent );
|
||||
m_nextFadeout = QPixmap(width(), m_nextPage->height());
|
||||
m_nextFadeout.fill(Qt::transparent);
|
||||
QPainter p(&m_nextFadeout);
|
||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
p.fillRect(m_nextFadeout.rect(), g);
|
||||
}
|
||||
|
||||
painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
if (m_previousPage->isVisible()) {
|
||||
painter.drawPixmap(QPoint(0,0), m_previousFadeout);
|
||||
}
|
||||
|
||||
if (m_nextPage->isVisible()) {
|
||||
painter.drawPixmap(QPoint(0,height()-m_nextFadeout.height()), m_nextFadeout);
|
||||
}
|
||||
painter.end();
|
||||
|
||||
|
||||
}
|
||||
|
||||
#include "moc_resultview.cpp"
|
|
@ -1,68 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2009 by Jacopo De Simoi <wilderkde@gmail.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 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; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef RESULTVIEW_H
|
||||
#define RESULTVIEW_H
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class Svg;
|
||||
}
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QToolButton>
|
||||
class ResultScene;
|
||||
class SharedResultData;
|
||||
|
||||
class ResultsView : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ResultsView(ResultScene *scene, SharedResultData *resultData, QWidget *parent = 0);
|
||||
~ResultsView();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *);
|
||||
void paintEvent(QPaintEvent *);
|
||||
void wheelEvent(QWheelEvent *);
|
||||
|
||||
private Q_SLOTS:
|
||||
void ensureVisibility(QGraphicsItem *item);
|
||||
void updateArrowsIcons();
|
||||
void updateArrowsVisibility();
|
||||
void previousPage();
|
||||
void nextPage();
|
||||
|
||||
private:
|
||||
void resetArrowsPosition();
|
||||
|
||||
ResultScene *m_resultScene;
|
||||
SharedResultData *m_resultData;
|
||||
QToolButton *m_previousPage;
|
||||
QToolButton *m_nextPage;
|
||||
Plasma::Svg *m_arrowSvg;
|
||||
QPixmap m_previousFadeout;
|
||||
QPixmap m_nextFadeout;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,87 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2009 by Aaron Seigo <aseigo@kde.org> *
|
||||
* *
|
||||
* 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; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#include "selectionbar.h"
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#include <QtGui/qstyleoption.h>
|
||||
#include <QTimer>
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include <Plasma/FrameSvg>
|
||||
|
||||
#include "resultitem.h"
|
||||
|
||||
SelectionBar::SelectionBar(QGraphicsWidget *parent)
|
||||
: Plasma::ItemBackground(parent),
|
||||
m_hideTimer(new QTimer(this))
|
||||
{
|
||||
// the hide timer is necessary because when calling QGraphicsScene::setFocusItem,
|
||||
// the selection is cleared first, then set. this causes acquireTarget to get called
|
||||
// multiple times, first with no selection. however, when the selection does go away
|
||||
// permanently, we do want to hide.
|
||||
m_hideTimer->setInterval(0);
|
||||
m_hideTimer->setSingleShot(true);
|
||||
connect(m_hideTimer, SIGNAL(timeout()), this, SLOT(actuallyHide()));
|
||||
}
|
||||
|
||||
void SelectionBar::acquireTarget()
|
||||
{
|
||||
QList<QGraphicsItem *> selection = scene()->selectedItems();
|
||||
if (selection.isEmpty()) {
|
||||
m_hideTimer->start();
|
||||
return;
|
||||
}
|
||||
|
||||
m_hideTimer->stop();
|
||||
//kDebug() << "showing an item!";
|
||||
setTargetItem(selection.first());
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
void SelectionBar::actuallyHide()
|
||||
{
|
||||
hide();
|
||||
}
|
||||
|
||||
QVariant SelectionBar::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
switch (change) {
|
||||
case ItemSceneChange: {
|
||||
if (scene()) {
|
||||
disconnect(scene(), SIGNAL(selectionChanged()), this, SLOT(acquireTarget()));
|
||||
}
|
||||
|
||||
QGraphicsScene *newScene = value.value<QGraphicsScene*>();
|
||||
if (newScene) {
|
||||
connect(newScene, SIGNAL(selectionChanged()), this, SLOT(acquireTarget()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QGraphicsWidget::itemChange(change, value);
|
||||
}
|
||||
|
||||
#include "moc_selectionbar.cpp"
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2009 by Aaron Seigo <aseigo@kde.org> *
|
||||
* *
|
||||
* 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; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef SELECTIONBAR_H
|
||||
#define SELECTIONBAR_H
|
||||
|
||||
#include <Plasma/ItemBackground>
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class FrameSvg;
|
||||
} // namespace Plasma
|
||||
|
||||
class ResultItem;
|
||||
|
||||
class SelectionBar : public Plasma::ItemBackground
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SelectionBar(QGraphicsWidget *parent);
|
||||
|
||||
protected:
|
||||
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
|
||||
|
||||
private Q_SLOTS:
|
||||
void acquireTarget();
|
||||
void actuallyHide();
|
||||
|
||||
private:
|
||||
QTimer *m_hideTimer;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2008 Ryan P. Bitanga <ryan.bitanga@gmail.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 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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QPoint>
|
||||
#include <QtGui/qevent.h>
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include "qs_completionbox.h"
|
||||
#include "qs_statusbar.h"
|
||||
|
||||
namespace QuickSand {
|
||||
|
||||
QsCompletionBox::QsCompletionBox(QWidget *parent)
|
||||
: KCompletionBox(parent),
|
||||
m_offset(0,0)
|
||||
{
|
||||
m_status = new QsStatusBar(this);
|
||||
connect(model(), SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(slotRowsChanged(QModelIndex,int,int)));
|
||||
connect(model(), SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(slotRowsChanged(QModelIndex,int,int)));
|
||||
connect(this, SIGNAL(currentRowChanged(int)), m_status, SLOT(slotCurrentRowChanged(int)));
|
||||
}
|
||||
|
||||
QRect QsCompletionBox::calculateGeometry() const
|
||||
{
|
||||
QRect geom = KCompletionBox::calculateGeometry();
|
||||
geom.setHeight(geom.height() + m_status->geometry().height());
|
||||
geom.setWidth(geom.width() * 3/4);
|
||||
return geom;
|
||||
}
|
||||
|
||||
QSize QsCompletionBox::minimumSizeHint() const
|
||||
{
|
||||
return sizeHint();
|
||||
}
|
||||
|
||||
QSize QsCompletionBox::sizeHint() const
|
||||
{
|
||||
return calculateGeometry().size();
|
||||
}
|
||||
|
||||
void QsCompletionBox::popup()
|
||||
{
|
||||
KCompletionBox::popup();
|
||||
resize(calculateGeometry().size());
|
||||
}
|
||||
|
||||
void QsCompletionBox::updateGeometries()
|
||||
{
|
||||
KCompletionBox::updateGeometries();
|
||||
int statusHeight = m_status->geometry().height();
|
||||
|
||||
// setGeometry(calculateGeometry());
|
||||
|
||||
setViewportMargins(0,0,0,statusHeight);
|
||||
|
||||
QRect vg = viewport()->geometry();
|
||||
int statusTop = vg.bottom();
|
||||
|
||||
m_status->setGeometry(vg.left(), statusTop, vg.width(), statusHeight);
|
||||
}
|
||||
|
||||
void QsCompletionBox::slotRowsChanged(const QModelIndex &, int, int)
|
||||
{
|
||||
int rows = model()->rowCount();
|
||||
m_status->setTotalRows(rows);
|
||||
}
|
||||
|
||||
QPoint QsCompletionBox::globalPositionHint() const
|
||||
{
|
||||
QWidget *p = qobject_cast<QWidget*>(parent());
|
||||
if (!p) {
|
||||
return QPoint();
|
||||
}
|
||||
return p->mapToGlobal(QPoint(p->width(), 22));
|
||||
}
|
||||
|
||||
} // Namespace QuickSand
|
||||
|
||||
#include "moc_qs_completionbox.cpp"
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2008 Ryan P. Bitanga <ryan.bitanga@gmail.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 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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
#ifndef QS_COMPLETIONBOX_H
|
||||
#define QS_COMPLETIONBOX_H
|
||||
|
||||
#include <KCompletionBox>
|
||||
|
||||
#include <QKeyEvent>
|
||||
|
||||
namespace QuickSand {
|
||||
|
||||
class QsStatusBar;
|
||||
|
||||
/**
|
||||
* A completion box with configurable offset
|
||||
* and a label that shows the current position.
|
||||
*/
|
||||
class QsCompletionBox : public KCompletionBox
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QsCompletionBox(QWidget *parent = 0);
|
||||
|
||||
/**
|
||||
* Set the offset of the completion box
|
||||
*/
|
||||
// void setOffset(int x, int y);
|
||||
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
QSize sizeHint() const;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void updateGeometries();
|
||||
public Q_SLOTS:
|
||||
void popup();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void slotRowsChanged(const QModelIndex & parent, int start, int end);
|
||||
|
||||
protected:
|
||||
QPoint globalPositionHint() const;
|
||||
// void resizeEvent(QResizeEvent *e);
|
||||
|
||||
QRect calculateGeometry() const;
|
||||
|
||||
private:
|
||||
QsStatusBar *m_status;
|
||||
QPoint m_offset;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,316 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2006 by Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright (C) 2007-2009 Ryan P. Bitanga <ryan.bitanga@gmail.com>
|
||||
* Copyright (C) 2008 by Davide Bettio <davide.bettio@kdemail.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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QBoxLayout>
|
||||
#include <QDesktopWidget>
|
||||
#include <QLabel>
|
||||
#include <QTimer>
|
||||
#include <QShortcut>
|
||||
#include <KAction>
|
||||
#include <KActionCollection>
|
||||
#include <KStandardGuiItem>
|
||||
#include <KWindowSystem>
|
||||
|
||||
//#include <Plasma/QueryAction>
|
||||
#include <Plasma/QueryMatch>
|
||||
#include <Plasma/RunnerManager>
|
||||
#include <Plasma/Svg>
|
||||
#include <Plasma/Theme>
|
||||
|
||||
#include "toolbutton.h"
|
||||
|
||||
#include "krunnerapp.h"
|
||||
#include "qs_dialog.h"
|
||||
#include "qs_matchview.h"
|
||||
#include "qs_querymatchitem.h"
|
||||
#include "qs_queryactionitem.h"
|
||||
|
||||
QsDialog::QsDialog(Plasma::RunnerManager *runnerManager, QWidget *parent)
|
||||
: KRunnerDialog(runnerManager, parent)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->setMargin(0);
|
||||
layout->setSpacing(0);
|
||||
|
||||
QHBoxLayout *hLayout = new QHBoxLayout();
|
||||
hLayout->setMargin(0);
|
||||
hLayout->setSpacing(0);
|
||||
|
||||
m_configButton = new ToolButton(this);
|
||||
m_configButton->setText(i18n("Settings"));
|
||||
m_configButton->setToolTip(i18n("Settings"));
|
||||
m_configButton->setIcon(m_iconSvg->pixmap(QLatin1String( "configure" )));
|
||||
connect(m_configButton, SIGNAL(clicked()), SLOT(toggleConfigDialog()));
|
||||
|
||||
m_activityButton = new ToolButton(this);
|
||||
KRunnerApp *krunnerApp = KRunnerApp::self();
|
||||
QAction *showSystemActivityAction = krunnerApp->actionCollection()->action(QLatin1String( "Show System Activity" ));
|
||||
m_activityButton->setDefaultAction(showSystemActivityAction);
|
||||
m_activityButton->setIcon(m_iconSvg->pixmap(QLatin1String( "status" )));
|
||||
|
||||
updateSystemActivityToolTip();
|
||||
connect(showSystemActivityAction, SIGNAL(globalShortcutChanged(QKeySequence)), this, SLOT(updateSystemActivityToolTip()));
|
||||
connect(showSystemActivityAction, SIGNAL(triggered(bool)), this, SLOT(close()));
|
||||
|
||||
m_singleRunnerIcon = new QLabel(this);
|
||||
|
||||
QLabel *label = new QLabel(this);
|
||||
label->setText(QLatin1String( "<b>QuickSand</b>" ));
|
||||
|
||||
const QColor textColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
|
||||
QPalette titlePallete = label->palette();
|
||||
titlePallete.setColor(QPalette::WindowText, textColor);
|
||||
label->setPalette(titlePallete);
|
||||
|
||||
QToolButton *m_closeButton = new ToolButton(this);
|
||||
KGuiItem guiItem = KStandardGuiItem::close();
|
||||
m_closeButton->setText(guiItem.text());
|
||||
m_closeButton->setToolTip(guiItem.text().remove(QLatin1Char( '&' )));
|
||||
m_closeButton->setIcon(m_iconSvg->pixmap(QLatin1String( "close" )));
|
||||
connect(m_closeButton, SIGNAL(clicked(bool)), this, SLOT(close()));
|
||||
|
||||
hLayout->addWidget(m_configButton);
|
||||
hLayout->addWidget(m_activityButton);
|
||||
hLayout->addWidget(m_singleRunnerIcon);
|
||||
hLayout->addStretch();
|
||||
hLayout->addWidget(label);
|
||||
hLayout->addStretch();
|
||||
hLayout->addWidget(m_closeButton);
|
||||
layout->addLayout(hLayout);
|
||||
|
||||
m_matchView = new QuickSand::QsMatchView(this);
|
||||
layout->addWidget(m_matchView);
|
||||
connect(m_matchView, SIGNAL(textChanged(QString)), m_matchView, SLOT(setTitle(QString)));
|
||||
|
||||
m_currentMatch = 0;
|
||||
|
||||
m_actionView = new QuickSand::QsMatchView(this);
|
||||
layout->addWidget(m_actionView);
|
||||
m_actionView->setTitle(i18n("Actions"));
|
||||
m_actionView->setCountingActions(true);
|
||||
m_actionView->hide();
|
||||
|
||||
connect(m_runnerManager, SIGNAL(matchesChanged(QList<Plasma::QueryMatch>)),
|
||||
this, SLOT(setMatches(QList<Plasma::QueryMatch>)));
|
||||
connect(m_matchView, SIGNAL(textChanged(QString)), this, SLOT(launchQuery(QString)));
|
||||
connect(m_matchView, SIGNAL(selectionChanged(MatchItem*)), this, SLOT(loadActions(MatchItem*)));
|
||||
connect(m_matchView, SIGNAL(itemActivated(MatchItem*)), this, SLOT(run(MatchItem*)));
|
||||
connect(m_actionView, SIGNAL(selectionChanged(MatchItem*)), this, SLOT(setAction(MatchItem*)));
|
||||
connect(m_actionView, SIGNAL(itemActivated(MatchItem*)), this, SLOT(run(MatchItem*)));
|
||||
|
||||
m_matchView->setFocus();
|
||||
|
||||
m_newQuery = true;
|
||||
|
||||
new QShortcut(QKeySequence(Qt::Key_Escape), this, SLOT(close()));
|
||||
}
|
||||
|
||||
QsDialog::~QsDialog()
|
||||
{}
|
||||
|
||||
// FIXME: We still have no notion of history... Actually adaptive search should partly take care of this
|
||||
void QsDialog::clearHistory()
|
||||
{}
|
||||
|
||||
void QsDialog::setConfigWidget(QWidget *w)
|
||||
{
|
||||
//Yet another code copy pasted from default interface, should we move this to a common place?
|
||||
const int screenId = qApp->desktop()->screenNumber(this);
|
||||
const int maxHeight = qApp->desktop()->availableGeometry(screenId).height();
|
||||
|
||||
int left, top, right, bottom;
|
||||
getContentsMargins(&left, &top, &right, &bottom);
|
||||
const int padding = top + bottom + m_activityButton->height();
|
||||
resize(width(), qMin(maxHeight, qMax(w->sizeHint().height() + padding, size().height())));
|
||||
|
||||
QVBoxLayout *layout = static_cast<QVBoxLayout*>(this->layout());
|
||||
layout->addWidget(w);
|
||||
m_matchView->hide();
|
||||
|
||||
connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(configWidgetDestroyed()));
|
||||
}
|
||||
|
||||
void QsDialog::configWidgetDestroyed()
|
||||
{
|
||||
QTimer::singleShot(0, this, SLOT(cleanupAfterConfigWidget()));
|
||||
}
|
||||
|
||||
void QsDialog::cleanupAfterConfigWidget()
|
||||
{
|
||||
m_matchView->show();
|
||||
m_matchView->setFocus();
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
void QsDialog::adjustInterface()
|
||||
{
|
||||
if (m_runnerManager->singleModeRunner()) {
|
||||
m_singleRunnerIcon->setPixmap(m_runnerManager->singleModeRunner()->icon().pixmap( QSize( 22, 22 )) );
|
||||
m_singleRunnerIcon->show();
|
||||
m_configButton->hide();
|
||||
} else {
|
||||
m_singleRunnerIcon->hide();
|
||||
m_configButton->show();
|
||||
}
|
||||
}
|
||||
|
||||
void QsDialog::display(const QString &term)
|
||||
{
|
||||
KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop());
|
||||
|
||||
adjustInterface();
|
||||
m_matchView->reset();
|
||||
m_actionView->reset();
|
||||
m_actionView->hide();
|
||||
adjustSize();
|
||||
m_matchView->setFocus();
|
||||
|
||||
//positionOnScreen will call QWidget::show anyways so we don't need to call it here
|
||||
positionOnScreen();
|
||||
KWindowSystem::forceActiveWindow(winId());
|
||||
if (term.isEmpty() && !m_runnerManager->singleMode()) {
|
||||
m_matchView->setTitle(QString());
|
||||
} else {
|
||||
m_matchView->setTitle(term);
|
||||
launchQuery(term);
|
||||
}
|
||||
}
|
||||
|
||||
void QsDialog::launchQuery(const QString &query)
|
||||
{
|
||||
if (query.isEmpty() && !m_runnerManager->singleMode()) {
|
||||
m_matchView->reset();
|
||||
} else {
|
||||
m_matchView->showLoading();
|
||||
}
|
||||
|
||||
m_runnerManager->launchQuery(query);
|
||||
m_newQuery = true;
|
||||
}
|
||||
|
||||
void QsDialog::run(MatchItem *item)
|
||||
{
|
||||
if (QuickSand::QueryMatchItem *match = qobject_cast<QuickSand::QueryMatchItem*>(item)) {
|
||||
m_runnerManager->run(match->match());
|
||||
close();
|
||||
} else if (qobject_cast<QuickSand::QueryActionItem*>(item)) {
|
||||
m_runnerManager->run(m_currentMatch->match());
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
void QsDialog::loadActions(MatchItem *item)
|
||||
{
|
||||
if (item == m_currentMatch) {
|
||||
return;
|
||||
}
|
||||
m_currentMatch = qobject_cast<QuickSand::QueryMatchItem*>(item);
|
||||
QList<MatchItem*> actions;
|
||||
if (m_currentMatch) {
|
||||
QList<QAction*> queryActions = m_runnerManager->actionsForMatch(m_currentMatch->match());
|
||||
foreach(QAction *action, queryActions) {
|
||||
MatchItem *m = new QuickSand::QueryActionItem(action);
|
||||
actions.append(m);
|
||||
}
|
||||
}
|
||||
if (actions.size()) {
|
||||
m_actionView->show();
|
||||
} else if (m_actionView->isVisible()) {
|
||||
m_actionView->hide();
|
||||
}
|
||||
adjustSize();
|
||||
m_actionView->setItems(actions, false);
|
||||
}
|
||||
|
||||
void QsDialog::setMatches(const QList<Plasma::QueryMatch> &matches)
|
||||
{
|
||||
QList<MatchItem*> items;
|
||||
QMultiMap<QString, Plasma::QueryMatch> temp;
|
||||
QMultiMap<QString, Plasma::QueryMatch>::iterator end = m_matches.end();
|
||||
foreach (const Plasma::QueryMatch &match, matches) {
|
||||
temp.insert(match.id(), match);
|
||||
// Do not create new MatchItems for existing matches when the query hasn't changed
|
||||
if (!m_newQuery && m_matches.find(match.id()) != end) {
|
||||
// kDebug() << "A match with id " << match.id() << " already exists.";
|
||||
QList<Plasma::QueryMatch> duplicates = m_matches.values(match.id());
|
||||
bool exists = false;
|
||||
foreach (const Plasma::QueryMatch &m, duplicates) {
|
||||
// FIXME: Matching the displayed text isn't always reliable
|
||||
// maybe adding an operator== to QueryMatch would help
|
||||
if (m.text() == match.text()) {
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
MatchItem *m = new QuickSand::QueryMatchItem(match);
|
||||
|
||||
//TODO: I'm leaving the switch because this feature has sence, but we have to find another way to implement it
|
||||
/* switch(match.type())
|
||||
{
|
||||
case Plasma::QueryMatch::ExactMatch:
|
||||
m->setBackgroundColor(QColor(Qt::yellow));
|
||||
break;
|
||||
case Plasma::QueryMatch::InformationalMatch:
|
||||
case Plasma::QueryMatch::HelperMatch:
|
||||
m->setBackgroundColor(QColor(Qt::blue));
|
||||
break;
|
||||
default:
|
||||
m->setBackgroundColor(QColor(Qt::green));
|
||||
break;
|
||||
}*/
|
||||
|
||||
items.append(m);
|
||||
}
|
||||
// kDebug() << "Add " << items.size() << " matches. Append?" << !m_newQuery;
|
||||
m_matchView->setItems(items, true, !m_newQuery);
|
||||
m_matches = temp;
|
||||
// If new matches are obtained for the same query, append them to the list
|
||||
m_newQuery = false;
|
||||
}
|
||||
|
||||
void QsDialog::setAction(MatchItem *item)
|
||||
{
|
||||
if (QuickSand::QueryActionItem *action = qobject_cast<QuickSand::QueryActionItem*>(item)) {
|
||||
m_currentMatch->match().setSelectedAction(action->action());
|
||||
}
|
||||
}
|
||||
|
||||
void QsDialog::updateSystemActivityToolTip()
|
||||
{
|
||||
/* Set the tooltip for the Show System Activity button to include the global shortcut */
|
||||
KRunnerApp *krunnerApp = KRunnerApp::self();
|
||||
KAction *showSystemActivityAction = qobject_cast<KAction *>(krunnerApp->actionCollection()->action(QLatin1String( "Show System Activity" )));
|
||||
if (showSystemActivityAction) {
|
||||
QString shortcut = showSystemActivityAction->globalShortcut().toString();
|
||||
if (shortcut.isEmpty()) {
|
||||
m_activityButton->setToolTip( showSystemActivityAction->toolTip() );
|
||||
} else {
|
||||
m_activityButton->setToolTip( i18nc("tooltip, shortcut", "%1 (%2)", showSystemActivityAction->toolTip(), shortcut));
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "moc_qs_dialog.cpp"
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2008 Ryan P. Bitanga <ryan.bitanga@gmail.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 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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
#ifndef QS_DIALOG_H
|
||||
#define QS_DIALOG_H
|
||||
|
||||
#include "krunnerdialog.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class QueryMatch;
|
||||
class RunnerManager;
|
||||
}
|
||||
|
||||
namespace QuickSand
|
||||
{
|
||||
class QsMatchView;
|
||||
class MatchItem;
|
||||
class QueryMatchItem;
|
||||
}
|
||||
|
||||
using QuickSand::MatchItem;
|
||||
|
||||
/**
|
||||
* This is an ugly test dialog
|
||||
* It's only real purpose is to test the MatchView widgets
|
||||
*/
|
||||
class QsDialog : public KRunnerDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QsDialog(Plasma::RunnerManager *runnerManager, QWidget *parent = 0);
|
||||
~QsDialog();
|
||||
|
||||
void display(const QString& term = QString());
|
||||
void clearHistory();
|
||||
void setConfigWidget(QWidget *w);
|
||||
|
||||
private slots:
|
||||
void run(MatchItem *item);
|
||||
void launchQuery(const QString &query);
|
||||
void setMatches(const QList<Plasma::QueryMatch> &matches);
|
||||
void loadActions(MatchItem *item);
|
||||
void setAction(MatchItem *item);
|
||||
void configWidgetDestroyed();
|
||||
void cleanupAfterConfigWidget();
|
||||
//afiestas: We should move this to krunnerdialog imho (I just copyied it atm)
|
||||
void updateSystemActivityToolTip();
|
||||
private:
|
||||
void adjustInterface();
|
||||
|
||||
bool m_newQuery;
|
||||
QLabel *m_singleRunnerIcon;
|
||||
QToolButton *m_configButton;
|
||||
QToolButton *m_activityButton;
|
||||
|
||||
QMultiMap<QString, Plasma::QueryMatch> m_matches;
|
||||
QuickSand::QsMatchView *m_matchView;
|
||||
QuickSand::QsMatchView *m_actionView;
|
||||
QuickSand::QueryMatchItem *m_currentMatch;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2008 Ryan P. Bitanga <ryan.bitanga@gmail.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 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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
#include <QGraphicsItemAnimation>
|
||||
#include <QIcon>
|
||||
#include <QPainter>
|
||||
|
||||
#include <KIcon>
|
||||
|
||||
#include "qs_matchitem.h"
|
||||
|
||||
namespace QuickSand
|
||||
{
|
||||
|
||||
MatchItem::MatchItem(const QIcon &icon, const QString &name, const QString &desc, QGraphicsWidget *parent)
|
||||
: QGraphicsWidget(parent),
|
||||
m_anim(0),
|
||||
m_name(name),
|
||||
m_desc(desc)
|
||||
{
|
||||
if (icon.isNull()) {
|
||||
m_icon = KIcon(QLatin1String( "unknown" ));
|
||||
} else {
|
||||
m_icon = icon;
|
||||
}
|
||||
setFlag(QGraphicsItem::ItemIsFocusable);
|
||||
setFlag(QGraphicsItem::ItemIsSelectable);
|
||||
setAcceptHoverEvents(true);
|
||||
resize(ITEM_SIZE, ITEM_SIZE);
|
||||
setToolTip(QString(QLatin1String( "%1: %2" )).arg(name).arg(desc));
|
||||
}
|
||||
|
||||
MatchItem::~MatchItem()
|
||||
{
|
||||
delete m_anim;
|
||||
}
|
||||
|
||||
QGraphicsItemAnimation* MatchItem::anim(bool create)
|
||||
{
|
||||
if (create) {
|
||||
delete m_anim;
|
||||
m_anim = new QGraphicsItemAnimation();
|
||||
m_anim->setItem(this);
|
||||
}
|
||||
return m_anim;
|
||||
}
|
||||
|
||||
void MatchItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
if (hasFocus() || isSelected()) {
|
||||
painter->drawPixmap(0, 0, m_icon.pixmap(64, 64, QIcon::Active));
|
||||
} else {
|
||||
painter->drawPixmap(0, 0, m_icon.pixmap(64, 64, QIcon::Disabled));
|
||||
}
|
||||
//TODO: Make items glow on hover and draw text over them
|
||||
}
|
||||
|
||||
void MatchItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
emit activated(this);
|
||||
}
|
||||
|
||||
} // namespace QuickSand
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2008 Ryan P. Bitanga <ryan.bitanga@gmail.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 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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
#ifndef QS_MATCHITEM_H
|
||||
#define QS_MATCHITEM_H
|
||||
|
||||
#include <QGraphicsWidget>
|
||||
#include <QIcon>
|
||||
|
||||
#include <QGraphicsItemAnimation>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
namespace QuickSand
|
||||
{
|
||||
// Deriving directly from QGraphicsItem causes crashes when animating
|
||||
class MatchItem : public QGraphicsWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MatchItem(const QIcon &icon, const QString &name, const QString &desc = QString(), QGraphicsWidget *parent = 0);
|
||||
~MatchItem();
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
|
||||
QString id() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
QString name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
QString description() const
|
||||
{
|
||||
return m_desc;
|
||||
}
|
||||
QIcon icon() const
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param create delete the current animation and create a new one
|
||||
* @return the animation associated with this item
|
||||
*/
|
||||
QGraphicsItemAnimation* anim(bool create = false);
|
||||
|
||||
static const int ITEM_SIZE = 64;
|
||||
signals:
|
||||
void activated(MatchItem *item);
|
||||
private:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *e);
|
||||
|
||||
QGraphicsItemAnimation *m_anim;
|
||||
QIcon m_icon;
|
||||
QString m_id;
|
||||
QString m_name;
|
||||
QString m_desc;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,693 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2009 Ryan P. Bitanga <ryan.bitanga@gmail.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 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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QGraphicsItemAnimation>
|
||||
#include <QtGui/qgraphicsitem.h>
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsWidget>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QStackedWidget>
|
||||
#include <QTimeLine>
|
||||
#include <QTimer>
|
||||
#include <QToolButton>
|
||||
#include <QShortcut>
|
||||
#include <QClipboard>
|
||||
#include <QApplication>
|
||||
|
||||
#include <KDebug>
|
||||
#include <KIcon>
|
||||
#include <KLineEdit>
|
||||
#include <KLocale>
|
||||
|
||||
#include <Plasma/Theme>
|
||||
|
||||
#include "qs_completionbox.h"
|
||||
#include "qs_statusbar.h"
|
||||
#include "qs_matchitem.h"
|
||||
#include "qs_matchview.h"
|
||||
#include "qs_querymatchitem.h"
|
||||
|
||||
//Widget dimensions
|
||||
const int WIDTH = 390;
|
||||
const int HEIGHT = 80; //10px overlap with text
|
||||
const int ICON_AREA_HEIGHT = 70; //3 px margins
|
||||
const int LARGE_ICON_PADDING = 3;
|
||||
const int SMALL_ICON_PADDING = 19; //(70 - ITEM_SIZE)/2
|
||||
//FIXME: Magic numbers galore...
|
||||
|
||||
namespace QuickSand{
|
||||
|
||||
class QsMatchView::Private
|
||||
{
|
||||
public:
|
||||
QLabel *m_titleLabel;
|
||||
QLabel *m_itemCountLabel;
|
||||
QToolButton *m_arrowButton;
|
||||
QStackedWidget *m_stack;
|
||||
QGraphicsScene *m_scene;
|
||||
QGraphicsView *m_view;
|
||||
KLineEdit *m_lineEdit;
|
||||
QsCompletionBox *m_compBox;
|
||||
QList<MatchItem*> m_items;
|
||||
QString m_searchTerm;
|
||||
QGraphicsRectItem *m_descRect;
|
||||
QGraphicsTextItem *m_descText;
|
||||
QTimeLine *m_timeLine;
|
||||
int m_currentItem;
|
||||
bool m_hasFocus : 1;
|
||||
bool m_itemsRemoved : 1;
|
||||
bool m_listVisible : 1;
|
||||
bool m_selectionMade : 1;
|
||||
bool m_itemCountSuffixItems : 1;
|
||||
};
|
||||
|
||||
QsMatchView::QsMatchView(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
d(new Private())
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
//Track focus because focus changes between internal widgets trigger focus events
|
||||
d->m_hasFocus = false;
|
||||
d->m_itemsRemoved = false;
|
||||
d->m_listVisible = true;
|
||||
d->m_selectionMade = false; //Prevent completion box from popping up once a user chooses a match
|
||||
|
||||
d->m_timeLine = new QTimeLine(150, this);
|
||||
|
||||
d->m_descRect = 0;
|
||||
d->m_descText = 0;
|
||||
|
||||
d->m_view = new QGraphicsView(this);
|
||||
d->m_view->setRenderHint(QPainter::Antialiasing);
|
||||
d->m_view->viewport()->setAutoFillBackground(false);
|
||||
d->m_view->setInteractive(true);
|
||||
d->m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
d->m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
d->m_view->setOptimizationFlag(QGraphicsView::DontSavePainterState);
|
||||
d->m_view->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
d->m_view->setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
d->m_scene = new QGraphicsScene(-WIDTH/2, 0, WIDTH, HEIGHT, this);
|
||||
d->m_view->setScene(d->m_scene);
|
||||
|
||||
d->m_currentItem = 0;
|
||||
|
||||
d->m_lineEdit = new KLineEdit(this);
|
||||
new QShortcut(QKeySequence(QLatin1String( "Ctrl+V" )), this, SLOT(pasteClipboard()));
|
||||
d->m_compBox = new QuickSand::QsCompletionBox(this);
|
||||
d->m_compBox->setTabHandling(false);
|
||||
|
||||
d->m_stack = new QStackedWidget(this);
|
||||
d->m_stack->addWidget(d->m_view);
|
||||
d->m_stack->addWidget(d->m_lineEdit);
|
||||
d->m_stack->setCurrentIndex(0);
|
||||
|
||||
const QColor textColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
|
||||
d->m_titleLabel = new QLabel(this);
|
||||
d->m_itemCountLabel = new QLabel(this);
|
||||
|
||||
QPalette labelPallete = d->m_itemCountLabel->palette();
|
||||
labelPallete.setColor(QPalette::WindowText, textColor);
|
||||
d->m_itemCountLabel->setPalette(labelPallete);
|
||||
d->m_titleLabel->setPalette(labelPallete);
|
||||
|
||||
d->m_itemCountSuffixItems = true;
|
||||
|
||||
d->m_arrowButton = new QToolButton(this);
|
||||
d->m_arrowButton->setFocusPolicy(Qt::NoFocus);
|
||||
d->m_arrowButton->setArrowType(Qt::RightArrow);
|
||||
Plasma::Theme *theme = Plasma::Theme::defaultTheme();
|
||||
QString buttonStyleSheet = QLatin1String( "QToolButton { border-radius: 4px; border: 0px; background-color: transparent }");
|
||||
buttonStyleSheet += QString(QLatin1String( "QToolButton:hover { border: 1px solid %1; }" ))
|
||||
.arg(theme->color(Plasma::Theme::HighlightColor).name());
|
||||
d->m_arrowButton->setStyleSheet(buttonStyleSheet);
|
||||
|
||||
QHBoxLayout *topLayout = new QHBoxLayout();
|
||||
topLayout->setSpacing(0);
|
||||
topLayout->setMargin(0);
|
||||
topLayout->addWidget(d->m_titleLabel);
|
||||
topLayout->addStretch();
|
||||
topLayout->addWidget(d->m_itemCountLabel);
|
||||
topLayout->addWidget(d->m_arrowButton);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(0);
|
||||
layout->setMargin(0);
|
||||
layout->addLayout(topLayout);
|
||||
layout->addWidget(d->m_stack);
|
||||
|
||||
connect(d->m_compBox, SIGNAL(currentRowChanged(int)), this, SLOT(scrollToItem(int)));
|
||||
connect(d->m_compBox, SIGNAL(activated(QString)), this, SLOT(showSelected()));
|
||||
connect(d->m_lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged(QString)));
|
||||
connect(d->m_arrowButton, SIGNAL(pressed()), this, SLOT(toggleView()));
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
QsMatchView::~QsMatchView()
|
||||
{
|
||||
qDeleteAll(d->m_items);
|
||||
d->m_items.clear();
|
||||
delete d;
|
||||
}
|
||||
|
||||
void QsMatchView::reset()
|
||||
{
|
||||
clear(true);
|
||||
|
||||
d->m_stack->setCurrentIndex(0);
|
||||
d->m_arrowButton->hide();
|
||||
d->m_listVisible = true;
|
||||
d->m_selectionMade = false;
|
||||
d->m_hasFocus = false;
|
||||
d->m_searchTerm = QString();
|
||||
d->m_compBox->clear();
|
||||
d->m_compBox->hide();
|
||||
d->m_itemCountLabel->setText(QString());
|
||||
|
||||
QGraphicsPixmapItem *p = new QGraphicsPixmapItem(KIcon(QLatin1String( "edit-find" )).pixmap(MatchItem::ITEM_SIZE));
|
||||
p->setPos(-MatchItem::ITEM_SIZE/2, LARGE_ICON_PADDING);
|
||||
d->m_scene->addItem(p);
|
||||
//Replace with a suitable message
|
||||
setDescriptionText(i18n("Type to search."));
|
||||
}
|
||||
|
||||
bool queryMatchCompare(MatchItem *a, MatchItem *b)
|
||||
{
|
||||
QueryMatchItem *m1 = qobject_cast<QueryMatchItem*>(a);
|
||||
QueryMatchItem *m2 = qobject_cast<QueryMatchItem*>(b);
|
||||
if (m1 && m2) {
|
||||
return m2->match() < m1->match();
|
||||
}
|
||||
return a < b;
|
||||
}
|
||||
|
||||
void QsMatchView::setItems(const QList<MatchItem*> &items, bool popup, bool append)
|
||||
{
|
||||
int spacing = MatchItem::ITEM_SIZE/2;
|
||||
|
||||
int pos = spacing;
|
||||
|
||||
if (!append) {
|
||||
clear(true);
|
||||
d->m_compBox->clear();
|
||||
d->m_items = items;
|
||||
} else {
|
||||
/*if (!d->m_items.isEmpty()) {
|
||||
pos += d->m_items.last()->pos().x();
|
||||
}*/
|
||||
d->m_items << items;
|
||||
}
|
||||
qStableSort(d->m_items.begin(), d->m_items.end(), queryMatchCompare);
|
||||
d->m_compBox->clear();
|
||||
|
||||
foreach(MatchItem *item, d->m_items) {
|
||||
if (item) {
|
||||
item->setPos(pos, SMALL_ICON_PADDING);
|
||||
item->scale(0.5, 0.5);
|
||||
pos += spacing;
|
||||
if (d->m_listVisible) {
|
||||
d->m_scene->addItem(item);
|
||||
}
|
||||
QString description;
|
||||
if (item->description().isEmpty()) {
|
||||
description = item->name();
|
||||
} else {
|
||||
description = QString(QLatin1String( "%1 (%2)" )).arg(item->name()).arg(item->description());
|
||||
}
|
||||
QListWidgetItem *wi = new QListWidgetItem(item->icon(), description, d->m_compBox);
|
||||
d->m_compBox->addItem(wi);
|
||||
}
|
||||
}
|
||||
d->m_itemsRemoved = false;
|
||||
setItemCount(d->m_items.size());
|
||||
|
||||
if (d->m_selectionMade) {
|
||||
//kDebug() << "A user selection was already made";
|
||||
return;
|
||||
}
|
||||
|
||||
//Ensure popup is shown if desired
|
||||
if (popup) {
|
||||
if (items.size()) {
|
||||
d->m_compBox->popup();
|
||||
d->m_compBox->setCurrentRow(0);
|
||||
} else {
|
||||
d->m_compBox->hide();
|
||||
}
|
||||
d->m_arrowButton->setArrowType(Qt::DownArrow);
|
||||
} else {
|
||||
d->m_currentItem = 0;
|
||||
showSelected();
|
||||
}
|
||||
}
|
||||
|
||||
void QsMatchView::setTitle(const QString &title)
|
||||
{
|
||||
d->m_titleLabel->setText(title);
|
||||
}
|
||||
|
||||
void QsMatchView::setItemCount(int count)
|
||||
{
|
||||
if (d->m_itemCountSuffixItems) {
|
||||
d->m_itemCountLabel->setText(i18np("1 item", "%1 items", count));
|
||||
} else {
|
||||
d->m_itemCountLabel->setText(i18np("1 action", "%1 actions", count));
|
||||
}
|
||||
|
||||
if (count) {
|
||||
d->m_arrowButton->show();
|
||||
}
|
||||
}
|
||||
|
||||
void QsMatchView::setCountingActions(bool actions)
|
||||
{
|
||||
d->m_itemCountSuffixItems = !actions;
|
||||
}
|
||||
|
||||
void QsMatchView::setDescriptionText(const QString &text)
|
||||
{
|
||||
const QColor textColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
|
||||
setDescriptionText(text, textColor);
|
||||
}
|
||||
|
||||
void QsMatchView::setDescriptionText(const QString &text, const QColor &color)
|
||||
{
|
||||
if (d->m_descRect) {
|
||||
d->m_scene->removeItem(d->m_descRect);
|
||||
delete d->m_descRect;
|
||||
d->m_descRect = 0;
|
||||
}
|
||||
|
||||
QColor bg(color);
|
||||
bg.setAlphaF(0.6);
|
||||
QBrush b(bg);
|
||||
|
||||
QPen p(QColor(0, 0, 0, 0));
|
||||
d->m_descRect = new QGraphicsRectItem(-WIDTH/2, 60, WIDTH, 20);
|
||||
d->m_descRect->setBrush(b);
|
||||
d->m_descRect->setPen(p);
|
||||
|
||||
QFontMetrics fm(font());
|
||||
|
||||
// Show ellipsis in the middle to distinguish between strings with identical
|
||||
// beginnings e.g. paths
|
||||
d->m_descText = new QGraphicsTextItem(fm.elidedText(text, Qt::ElideMiddle, WIDTH), d->m_descRect);
|
||||
//Center text
|
||||
d->m_descText->setPos(-(d->m_descText->boundingRect().width()/2), 60);
|
||||
|
||||
d->m_scene->addItem(d->m_descRect);
|
||||
}
|
||||
|
||||
void QsMatchView::clearItems()
|
||||
{
|
||||
if (!d->m_itemsRemoved) {
|
||||
foreach (MatchItem *item, d->m_items) {
|
||||
d->m_scene->removeItem(item);
|
||||
}
|
||||
d->m_itemsRemoved = true;
|
||||
}
|
||||
}
|
||||
|
||||
void QsMatchView::clear(bool deleteItems)
|
||||
{
|
||||
if (!deleteItems) {
|
||||
clearItems();
|
||||
} else {
|
||||
d->m_items.clear();
|
||||
d->m_itemsRemoved = false;
|
||||
}
|
||||
d->m_scene->clear();
|
||||
d->m_descRect = 0;
|
||||
}
|
||||
|
||||
void QsMatchView::toggleView()
|
||||
{
|
||||
//It might be better not to rely on m_arrowButton...
|
||||
//should make things more readable
|
||||
if (d->m_arrowButton->arrowType() == Qt::RightArrow) {
|
||||
showList();
|
||||
} else {
|
||||
showSelected();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Fix animation
|
||||
void QsMatchView::showLoading()
|
||||
{
|
||||
clear(true);
|
||||
const QColor textColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
|
||||
d->m_descText = new QGraphicsTextItem(i18n("Loading..."), d->m_descRect);
|
||||
d->m_descText->setDefaultTextColor(textColor);
|
||||
QFontMetrics fm(d->m_descText->font());
|
||||
|
||||
//Center text
|
||||
d->m_descText->setPos(-(d->m_descText->boundingRect().width()/2), (HEIGHT - fm.height())/2);
|
||||
d->m_scene->addItem(d->m_descText);
|
||||
}
|
||||
|
||||
void QsMatchView::showList()
|
||||
{
|
||||
if (d->m_items.size()) {
|
||||
clear();
|
||||
|
||||
foreach (MatchItem *item, d->m_items) {
|
||||
d->m_scene->addItem(item);
|
||||
}
|
||||
|
||||
d->m_itemsRemoved = false;
|
||||
d->m_arrowButton->setArrowType(Qt::DownArrow);
|
||||
|
||||
//Restore highlighted icon
|
||||
focusItem(d->m_currentItem);
|
||||
//Popup the completion box - should make this configurable
|
||||
showPopup();
|
||||
}
|
||||
d->m_listVisible = true;
|
||||
}
|
||||
|
||||
void QsMatchView::showSelected()
|
||||
{
|
||||
if (!d->m_items.size()) {
|
||||
if (d->m_searchTerm.isEmpty()) {
|
||||
reset();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
MatchItem *it = d->m_items[d->m_currentItem];
|
||||
if (!it) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->m_listVisible = false;
|
||||
d->m_arrowButton->setArrowType(Qt::RightArrow);
|
||||
|
||||
clear();
|
||||
|
||||
d->m_stack->setCurrentIndex(0);
|
||||
|
||||
QGraphicsPixmapItem *pixmap = new QGraphicsPixmapItem(it->icon().pixmap(64));
|
||||
|
||||
pixmap->setPos(-WIDTH/2 + 5, LARGE_ICON_PADDING);
|
||||
|
||||
Plasma::Theme *theme = Plasma::Theme::defaultTheme();
|
||||
QColor c = theme->color(Plasma::Theme::TextColor);
|
||||
|
||||
QGraphicsTextItem *name = new QGraphicsTextItem();
|
||||
//TODO: Modify QFont instead of using setHtml?
|
||||
name->setHtml(QString(QLatin1String( "<b>%1</b>" )).arg(it->name()));
|
||||
name->setDefaultTextColor(c);
|
||||
QFontMetrics fm(name->font());
|
||||
|
||||
int tm = ICON_AREA_HEIGHT/2 - fm.height();
|
||||
name->setPos(-115, tm);
|
||||
|
||||
QGraphicsTextItem *desc = new QGraphicsTextItem(it->description());
|
||||
desc->setDefaultTextColor(c);
|
||||
desc->setPos(-115, ICON_AREA_HEIGHT/2);
|
||||
|
||||
d->m_scene->addItem(name);
|
||||
d->m_scene->addItem(desc);
|
||||
d->m_scene->addItem(pixmap);
|
||||
|
||||
emit selectionChanged(it);
|
||||
|
||||
d->m_compBox->hide();
|
||||
}
|
||||
|
||||
void QsMatchView::focusItem(int index)
|
||||
{
|
||||
if (!d->m_items.size()) {
|
||||
if (d->m_searchTerm.isEmpty()) {
|
||||
reset();
|
||||
} else {
|
||||
setDescriptionText(i18n("No results found."));
|
||||
}
|
||||
emit selectionChanged(0);
|
||||
return;
|
||||
}
|
||||
if (index > -1 && index < d->m_items.size()) {
|
||||
MatchItem *it = d->m_items[index];
|
||||
d->m_scene->setFocusItem(it);
|
||||
QString description;
|
||||
if (it->description().isEmpty()) {
|
||||
description = it->name();
|
||||
} else {
|
||||
description = QString(QLatin1String( "%1 (%2)" )).arg(it->name()).arg(it->description());
|
||||
}
|
||||
setDescriptionText(description);
|
||||
emit selectionChanged(it);
|
||||
}
|
||||
}
|
||||
|
||||
void QsMatchView::selectItem(int index)
|
||||
{
|
||||
Q_UNUSED(index)
|
||||
showSelected();
|
||||
}
|
||||
|
||||
void QsMatchView::finishAnimation()
|
||||
{
|
||||
if (d->m_timeLine->state() == QTimeLine::Running) {
|
||||
d->m_timeLine->setCurrentTime(d->m_timeLine->duration());
|
||||
}
|
||||
}
|
||||
|
||||
void QsMatchView::scrollLeft()
|
||||
{
|
||||
if (d->m_currentItem > 0){
|
||||
--d->m_currentItem;
|
||||
} else {
|
||||
d->m_currentItem = d->m_items.size() - 1;
|
||||
}
|
||||
|
||||
finishAnimation();
|
||||
foreach (MatchItem *item, d->m_items) {
|
||||
QGraphicsItemAnimation *anim = item->anim(true);
|
||||
int spacing = MatchItem::ITEM_SIZE/2;
|
||||
int y = SMALL_ICON_PADDING;
|
||||
int x = -spacing;
|
||||
int index = d->m_items.indexOf(item);
|
||||
if (index == d->m_currentItem) {
|
||||
anim->setScaleAt(1, 1, 1);
|
||||
y = LARGE_ICON_PADDING;
|
||||
} else {
|
||||
if ((!index && d->m_currentItem == d->m_items.size() - 1)
|
||||
|| index == d->m_currentItem + 1) {
|
||||
x = item->pos().x() + spacing*2;
|
||||
} else {
|
||||
x = item->pos().x() + spacing;
|
||||
}
|
||||
anim->setScaleAt(0, 0.5, 0.5);
|
||||
anim->setScaleAt(1, 0.5, 0.5);
|
||||
}
|
||||
anim->setPosAt(1.0, QPointF(x, y));
|
||||
anim->setTimeLine(d->m_timeLine);
|
||||
}
|
||||
d->m_timeLine->start();
|
||||
focusItem(d->m_currentItem);
|
||||
}
|
||||
|
||||
void QsMatchView::scrollRight()
|
||||
{
|
||||
if (d->m_currentItem < d->m_items.size() - 1) {
|
||||
++d->m_currentItem;
|
||||
} else {
|
||||
d->m_currentItem = 0;
|
||||
}
|
||||
|
||||
finishAnimation();
|
||||
foreach (MatchItem *item, d->m_items) {
|
||||
QGraphicsItemAnimation *anim = item->anim(true);
|
||||
int spacing = MatchItem::ITEM_SIZE/2;
|
||||
int y = SMALL_ICON_PADDING;
|
||||
int x = -spacing;
|
||||
if (d->m_items.indexOf(item) == d->m_currentItem) {
|
||||
anim->setScaleAt(1, 1, 1);
|
||||
y = LARGE_ICON_PADDING;
|
||||
} else {
|
||||
anim->setScaleAt(0, 0.5, 0.5);
|
||||
anim->setScaleAt(1, 0.5, 0.5);
|
||||
x = item->pos().x() - spacing;
|
||||
}
|
||||
anim->setPosAt(1.0, QPointF(x, y));
|
||||
anim->setTimeLine(d->m_timeLine);
|
||||
}
|
||||
d->m_timeLine->start();
|
||||
focusItem(d->m_currentItem);
|
||||
}
|
||||
|
||||
void QsMatchView::scrollToItem(int index)
|
||||
{
|
||||
if (index < 0 || d->m_items.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int oldIndex = d->m_currentItem;
|
||||
|
||||
//already at this item, make sure that the icon has the correct size etc.
|
||||
if (index == oldIndex) {
|
||||
scrollRight();
|
||||
scrollLeft();
|
||||
return;
|
||||
}
|
||||
|
||||
int times = index - oldIndex;
|
||||
bool isRight = times > 0;
|
||||
times = qAbs(times);
|
||||
|
||||
while (times) {
|
||||
if (isRight) {
|
||||
scrollRight();
|
||||
} else {
|
||||
scrollLeft();
|
||||
}
|
||||
--times;
|
||||
}
|
||||
}
|
||||
|
||||
void QsMatchView::showPopup()
|
||||
{
|
||||
if (d->m_hasFocus && d->m_items.size()) {
|
||||
//Prevent triggering of scroll to item
|
||||
disconnect(d->m_compBox, SIGNAL(currentRowChanged(int)), this, SLOT(scrollToItem(int)));
|
||||
d->m_compBox->popup();
|
||||
QListWidgetItem *item = d->m_compBox->item(d->m_currentItem);
|
||||
if (item) {
|
||||
d->m_compBox->scrollToItem(item, QAbstractItemView::PositionAtTop);
|
||||
d->m_compBox->setCurrentItem(item, QItemSelectionModel::SelectCurrent);
|
||||
}
|
||||
connect(d->m_compBox, SIGNAL(currentRowChanged(int)), this, SLOT(scrollToItem(int)));
|
||||
}
|
||||
}
|
||||
|
||||
void QsMatchView::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
QWidget::resizeEvent(e);
|
||||
QTimer::singleShot(150, this, SLOT(showPopup()));
|
||||
}
|
||||
|
||||
void QsMatchView::focusInEvent(QFocusEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
if (!d->m_hasFocus) {
|
||||
d->m_hasFocus = true;
|
||||
showList();
|
||||
}
|
||||
}
|
||||
|
||||
void QsMatchView::focusOutEvent(QFocusEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
if (hasFocus()) {
|
||||
return;
|
||||
}
|
||||
d->m_hasFocus = false;
|
||||
showSelected();
|
||||
}
|
||||
|
||||
void QsMatchView::pasteClipboard()
|
||||
{
|
||||
QClipboard *clip = qApp->clipboard();
|
||||
QString text = clip->text();
|
||||
|
||||
if (!text.isEmpty()) {
|
||||
d->m_lineEdit->setText(text);
|
||||
d->m_searchTerm = text;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Make it possible to disable text mode
|
||||
void QsMatchView::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
//Do not handle non-alphanumeric events
|
||||
if (e->modifiers() & ~Qt::ShiftModifier) {
|
||||
QWidget::keyPressEvent(e);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e->key()) {
|
||||
case Qt::Key_Period:
|
||||
//Switch to line edit
|
||||
d->m_stack->setCurrentIndex(1);
|
||||
d->m_lineEdit->setFocus();
|
||||
break;
|
||||
case Qt::Key_Backspace:
|
||||
//d->m_stack->setCurrentIndex(0);
|
||||
d->m_searchTerm.chop(1);
|
||||
setTitle(d->m_searchTerm);
|
||||
d->m_lineEdit->setText(d->m_searchTerm);
|
||||
return;
|
||||
case Qt::Key_Left:
|
||||
if (!d->m_listVisible) {
|
||||
showList();
|
||||
}
|
||||
scrollLeft();
|
||||
return;
|
||||
case Qt::Key_Right:
|
||||
if (!d->m_listVisible) {
|
||||
showList();
|
||||
}
|
||||
scrollRight();
|
||||
return;
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Return:
|
||||
//Do not activate item if popup is open
|
||||
if (d->m_compBox->isVisible()) {
|
||||
d->m_compBox->hide();
|
||||
} else if (d->m_items.size() && d->m_currentItem > -1
|
||||
&& d->m_currentItem < d->m_items.size()) {
|
||||
emit itemActivated(d->m_items[d->m_currentItem]);
|
||||
}
|
||||
d->m_selectionMade = true;
|
||||
showSelected();
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//Don't add control characters to the search term
|
||||
foreach (const QChar &c, e->text()) {
|
||||
if (c.isPrint()) {
|
||||
if (d->m_stack->currentIndex() == 1) {
|
||||
d->m_searchTerm = d->m_lineEdit->text() + c;
|
||||
} else {
|
||||
d->m_searchTerm += c;
|
||||
}
|
||||
d->m_selectionMade = false;
|
||||
}
|
||||
}
|
||||
// If line edit has focus, not all keypresses make it to
|
||||
// the parent widget, hence the internal search term is
|
||||
// out of date
|
||||
if (!d->m_lineEdit->hasFocus()) {
|
||||
d->m_lineEdit->setText(d->m_searchTerm);
|
||||
}
|
||||
QWidget::keyPressEvent(e);
|
||||
}
|
||||
|
||||
} // namespace QuickSand
|
||||
|
||||
#include "moc_qs_matchview.cpp"
|
|
@ -1,165 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2008 Ryan P. Bitanga <ryan.bitanga@gmail.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 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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
#ifndef QS_MATCHVIEW_H
|
||||
#define QS_MATCHVIEW_H
|
||||
|
||||
#include <QList>
|
||||
#include <QWidget>
|
||||
|
||||
#include <QFocusEvent>
|
||||
class QKeyPressEvent;
|
||||
#include <QResizeEvent>
|
||||
|
||||
namespace QuickSand {
|
||||
|
||||
class MatchItem;
|
||||
|
||||
/**
|
||||
* @class QsMatchView
|
||||
* @short A class to visualize a set of items
|
||||
*
|
||||
* QsMatchView is composed of a title label, an item count label,
|
||||
* a visualization box, and a popup completion box. The visualization
|
||||
* box has three modes: scrolling icon, selected item, and text mode.
|
||||
* The scrolling icon mode visualizes all items as a single horizontal
|
||||
* row of icons. Scrolling is controlled by either the completion box
|
||||
* or the view itself.
|
||||
*/
|
||||
class QsMatchView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QsMatchView(QWidget *parent = 0);
|
||||
~QsMatchView();
|
||||
|
||||
/**
|
||||
* Removes all items from the scene
|
||||
*/
|
||||
void clear(bool deleteItems = false);
|
||||
/**
|
||||
* Removes items from the scene and places default find message
|
||||
*/
|
||||
void reset();
|
||||
/**
|
||||
* Shows the loading animation
|
||||
*/
|
||||
void showLoading();
|
||||
/**
|
||||
* Sets the list of items to be displayed on screen
|
||||
* @param items The list of items to display
|
||||
* @param popup Display the popup completion box
|
||||
* @param append Append items to the current list instead of replacing it
|
||||
*/
|
||||
void setItems(const QList<MatchItem*> &items, bool popup = true, bool append = false);
|
||||
|
||||
/**
|
||||
* Sets the item count text on the upper right hand corner
|
||||
* Defaults to "items"
|
||||
*/
|
||||
void setCountingActions(bool actions);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* Sets the title text on the upper left hand corner of the widget
|
||||
*/
|
||||
void setTitle(const QString &title);
|
||||
/**
|
||||
* Display the popup
|
||||
*/
|
||||
void showPopup();
|
||||
private slots:
|
||||
/**
|
||||
* Switches between Icon Parade and Selected Item modes
|
||||
*/
|
||||
void toggleView();
|
||||
void scrollToItem(int index);
|
||||
/**
|
||||
* Uses whole view to display selected item and hides all other matches
|
||||
*/
|
||||
void showSelected();
|
||||
/**
|
||||
* Shows a scrolling list of icons for each match
|
||||
*/
|
||||
void showList();
|
||||
/**
|
||||
* Paste the content of the clipboard to the lineedit
|
||||
*/
|
||||
void pasteClipboard();
|
||||
signals:
|
||||
/**
|
||||
* Emitted when the user presser enter
|
||||
*/
|
||||
void itemActivated(MatchItem *item);
|
||||
/**
|
||||
* Emitted when the user changes selection through either the completion
|
||||
* box or the scrolling icon view
|
||||
*/
|
||||
void selectionChanged(MatchItem *item);
|
||||
/**
|
||||
* Emitted when the internal query string changes
|
||||
*/
|
||||
void textChanged(const QString &text);
|
||||
private:
|
||||
/**
|
||||
* Sets the text in the bottom portion of the widget
|
||||
* @param text Text to display
|
||||
* @param color Color of the rectangle behind the text
|
||||
*/
|
||||
void setDescriptionText(const QString &text, const QColor &color);
|
||||
/**
|
||||
* Convenience method. Calls setDescriptionText(text, Plasma::Theme.color())
|
||||
*/
|
||||
void setDescriptionText(const QString &text);
|
||||
|
||||
/**
|
||||
* Removes match items from scene but does not delete them
|
||||
*/
|
||||
void clearItems();
|
||||
|
||||
/**
|
||||
* Selects item at the specified index
|
||||
*/
|
||||
void selectItem(int index);
|
||||
/**
|
||||
* Highlights item and centers item when in scrolling icon mode
|
||||
*/
|
||||
void focusItem(int index);
|
||||
void scrollLeft();
|
||||
void scrollRight();
|
||||
|
||||
void setItemCount(int items);
|
||||
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void focusInEvent(QFocusEvent *event);
|
||||
void focusOutEvent(QFocusEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
/**
|
||||
* If there is already an animation and a new one should start, then the old
|
||||
* will be finished
|
||||
*/
|
||||
void finishAnimation();
|
||||
|
||||
class Private;
|
||||
Private* const d;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008 Ryan P. Bitanga <ryan.bitanga@gmail.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 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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
//#include <Plasma/QueryAction>
|
||||
#include <QAction>
|
||||
|
||||
#include "qs_queryactionitem.h"
|
||||
|
||||
namespace QuickSand
|
||||
{
|
||||
|
||||
QueryActionItem::QueryActionItem(QAction *action, QGraphicsWidget *parent)
|
||||
: MatchItem(action->icon(), action->text(), QString(), parent),
|
||||
m_action(action)
|
||||
{
|
||||
}
|
||||
|
||||
QAction* QueryActionItem::action()
|
||||
{
|
||||
return m_action;
|
||||
}
|
||||
|
||||
} // namespace QuickSand
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008 Ryan P. Bitanga <ryan.bitanga@gmail.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 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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
#ifndef QS_QUERYACTIONITEM_H
|
||||
#define QS_QUERYACTIONITEM_H
|
||||
|
||||
#include "qs_matchitem.h"
|
||||
|
||||
/*namespace Plasma
|
||||
{
|
||||
class QueryAction;
|
||||
}*/
|
||||
|
||||
#include <QAction>
|
||||
|
||||
namespace QuickSand
|
||||
{
|
||||
class QueryActionItem : public MatchItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QueryActionItem(QAction *action, QGraphicsWidget *parent = 0);
|
||||
QAction* action();
|
||||
private:
|
||||
QAction *m_action;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008 Ryan P. Bitanga <ryan.bitanga@gmail.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 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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
#include "qs_querymatchitem.h"
|
||||
|
||||
namespace QuickSand
|
||||
{
|
||||
|
||||
QueryMatchItem::QueryMatchItem(const Plasma::QueryMatch &match, QGraphicsWidget *parent)
|
||||
: MatchItem(match.icon(), match.text(), match.subtext(), parent),
|
||||
m_match(match)
|
||||
{}
|
||||
|
||||
Plasma::QueryMatch& QueryMatchItem::match()
|
||||
{
|
||||
return m_match;
|
||||
}
|
||||
|
||||
} // namespace QuickSand
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008 Ryan P. Bitanga <ryan.bitanga@gmail.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 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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
#ifndef QS_QUERYMATCHITEM_H
|
||||
#define QS_QUERYMATCHITEM_H
|
||||
|
||||
#include <Plasma/QueryMatch>
|
||||
|
||||
#include "qs_matchitem.h"
|
||||
|
||||
namespace QuickSand
|
||||
{
|
||||
class QueryMatchItem : public MatchItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QueryMatchItem(const Plasma::QueryMatch &match, QGraphicsWidget *parent = 0);
|
||||
Plasma::QueryMatch& match();
|
||||
private:
|
||||
Plasma::QueryMatch m_match;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2008 Ryan P. Bitanga <ryan.bitanga@gmail.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 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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
#include <QStyle>
|
||||
#include <QtGui/qstyleoption.h>
|
||||
#include <QStylePainter>
|
||||
|
||||
#include <KGlobalSettings>
|
||||
#include <KDebug>
|
||||
#include <KLocale>
|
||||
|
||||
#include "qs_statusbar.h"
|
||||
|
||||
namespace QuickSand {
|
||||
|
||||
QsStatusBar::QsStatusBar(QWidget *parent)
|
||||
: QLabel(parent),
|
||||
m_currentItem(0),
|
||||
m_totalItems(0)
|
||||
{
|
||||
}
|
||||
|
||||
// Patterned after QHeaderView
|
||||
void QsStatusBar::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QStylePainter painter(this);
|
||||
|
||||
QRect rect(0, 0, geometry().width(), geometry().height());
|
||||
|
||||
QStyleOptionHeader opt;
|
||||
opt.initFrom(this);
|
||||
opt.state = QStyle::State_None | QStyle::State_Raised;
|
||||
opt.state |= QStyle::State_Horizontal;
|
||||
opt.state |= QStyle::State_Enabled;
|
||||
|
||||
opt.rect = rect;
|
||||
opt.section = 0;
|
||||
opt.textAlignment = Qt::AlignRight;
|
||||
|
||||
opt.iconAlignment = Qt::AlignVCenter;
|
||||
opt.text = i18nc("%1 current item number, %2 total number of items","%1 of %2", m_currentItem, m_totalItems);
|
||||
|
||||
|
||||
opt.position = QStyleOptionHeader::OnlyOneSection;
|
||||
opt.orientation = Qt::Horizontal;
|
||||
|
||||
QFont font = painter.font();
|
||||
font.setPointSize(qMax(font.pointSize() - 2,
|
||||
KGlobalSettings::smallestReadableFont().pointSize()));
|
||||
painter.setFont(font);
|
||||
|
||||
painter.drawControl(QStyle::CE_Header, opt);
|
||||
}
|
||||
|
||||
void QsStatusBar::setTotalRows(int total)
|
||||
{
|
||||
m_totalItems = total;
|
||||
}
|
||||
|
||||
void QsStatusBar::slotCurrentRowChanged(int newRow)
|
||||
{
|
||||
m_currentItem = newRow + 1;
|
||||
update();
|
||||
}
|
||||
|
||||
} //namespace QuickSand
|
||||
|
||||
#include "moc_qs_statusbar.cpp"
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2008 Ryan P. Bitanga <ryan.bitanga@gmail.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 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; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
||||
*/
|
||||
|
||||
#ifndef QS_STATUSBAR_H
|
||||
#define QS_STATUSBAR_H
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
namespace QuickSand {
|
||||
/**
|
||||
* A small label providing status bar functionality for QListViews
|
||||
*/
|
||||
class QsStatusBar : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QsStatusBar(QWidget *parent = 0);
|
||||
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
/**
|
||||
* Sets the total rows in the QListView
|
||||
*/
|
||||
void setTotalRows(int rows);
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* Updates the current row index
|
||||
*/
|
||||
void slotCurrentRowChanged(int newRow);
|
||||
|
||||
private:
|
||||
QString m_message;
|
||||
int m_currentItem;
|
||||
int m_totalItems;
|
||||
};
|
||||
} // namespace QuickSand
|
||||
|
||||
#endif
|
|
@ -1,68 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
|
||||
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
|
||||
<kcfgfile name="krunnerrc" />
|
||||
<include>KGlobalSettings</include>
|
||||
<include>ksysguard/processui/ProcessModel.h</include>
|
||||
<include>ksysguard/processui/ProcessFilter.h</include>
|
||||
<!-- generated by KConfig XTraKtor -->
|
||||
<group name="General">
|
||||
<entry key="Interface" type="Enum">
|
||||
<label>The interface style to use in KRunner</label>
|
||||
<choices>
|
||||
<choice name="CommandOriented"/>
|
||||
<choice name="TaskOriented"/>
|
||||
</choices>
|
||||
<default>CommandOriented</default>
|
||||
</entry>
|
||||
<entry key="FreeFloating" type="bool">
|
||||
<label>Set to true to show the interface in a freely floating dialog instead of at the top of the screen</label>
|
||||
<default>false</default>
|
||||
</entry>
|
||||
<entry key="QueryTextCompletionMode" type="Int">
|
||||
<default code="true">(int)KGlobalSettings::CompletionMan</default>
|
||||
<label>Completion mode used for the query text.</label>
|
||||
</entry>
|
||||
|
||||
<entry name="PastQueries" key="PastQueries" type="StringList">
|
||||
<default></default>
|
||||
<label>History if past queries successfully completed</label>
|
||||
<whatsthis></whatsthis>
|
||||
</entry>
|
||||
</group>
|
||||
|
||||
<group name="TaskDialog">
|
||||
|
||||
<entry key="KeepAbove" name="KeepTaskDialogAbove" type="Bool">
|
||||
<default>true</default>
|
||||
<label>Whether to keep the tasks dialog above other windows when shown.</label>
|
||||
<whatsthis></whatsthis>
|
||||
</entry>
|
||||
|
||||
<entry key="units" type="Int">
|
||||
<default><code>ProcessModel::UnitsKB</code></default>
|
||||
</entry>
|
||||
|
||||
<entry key="showTotals" type="Bool">
|
||||
<default>true</default>
|
||||
</entry>
|
||||
|
||||
<entry key="filterState" type="Int">
|
||||
<default><code>ProcessFilter::AllProcesses</code></default>
|
||||
</entry>
|
||||
|
||||
<entry key="updateIntervalMSecs" type="Int">
|
||||
<default>2000</default>
|
||||
<min>0</min>
|
||||
</entry>
|
||||
|
||||
<entry key="version" type="Int">
|
||||
<default>0</default>
|
||||
<min>0</min>
|
||||
</entry>
|
||||
|
||||
</group>
|
||||
|
||||
</kcfg>
|
|
@ -1,4 +0,0 @@
|
|||
File=krunner.kcfg
|
||||
ClassName=KRunnerSettings
|
||||
Singleton=true
|
||||
Mutators=true
|
|
@ -1,86 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Exec=krunner
|
||||
StartupNotify=false
|
||||
Name=Command Runner
|
||||
Name[ar]=منفّذ الأوامر
|
||||
Name[ast]=Execución d'órdenes
|
||||
Name[be@latin]=Vykanańnie zahadaŭ
|
||||
Name[bg]=Команда
|
||||
Name[bn]=কমান্ড চালক
|
||||
Name[bn_IN]=কমান্ড সঞ্চালন ব্যবস্থা
|
||||
Name[bs]=Izvođač naredbi
|
||||
Name[ca]=Execució d'ordres
|
||||
Name[ca@valencia]=Execució d'ordes
|
||||
Name[cs]=Spouštěč příkazů
|
||||
Name[csb]=Pòlét
|
||||
Name[da]=Kør kommando
|
||||
Name[de]=Programmstarter
|
||||
Name[el]=Εκτελεστής εντολών
|
||||
Name[en_GB]=Command Runner
|
||||
Name[eo]=Ruli komandojn
|
||||
Name[es]=Ejecución de órdenes
|
||||
Name[et]=Käsu käivitaja
|
||||
Name[eu]=Komando-exekutatzailea
|
||||
Name[fa]=اجراکننده فرمان
|
||||
Name[fi]=Työpöydän komentoikkuna
|
||||
Name[fr]=Lanceur de commandes
|
||||
Name[fy]=Kommando rinner
|
||||
Name[ga]=Feidhmitheoir Orduithe
|
||||
Name[gl]=Execución de ordes
|
||||
Name[gu]=આદેશ ચલાવનાર
|
||||
Name[he]=מריץ הפקודות
|
||||
Name[hi]=कमांड चलाने वाला
|
||||
Name[hne]=कमांड चलाय वाला
|
||||
Name[hr]=Pokretač naredbi
|
||||
Name[hsb]=Wuwjedowar přikazow
|
||||
Name[hu]=Parancsbevitel
|
||||
Name[ia]=Executor de commando
|
||||
Name[id]=Pelari Perintah
|
||||
Name[is]=Skipanakeyrsla
|
||||
Name[ja]=コマンド Runner
|
||||
Name[kk]=Команданы жегуші
|
||||
Name[km]=កម្មវិធីរត់ពាក្យបញ្ជា
|
||||
Name[kn]=ಆದೇಶ ಚಾಲಕ
|
||||
Name[ko]=명령 실행기
|
||||
Name[lt]=Komandų paleidiklis
|
||||
Name[lv]=Komandu palaidējs
|
||||
Name[mai]=कमांड चलाबै बला
|
||||
Name[mk]=Извршувач на наредби
|
||||
Name[ml]=ആജ്ഞ പ്രവര്ത്തിപ്പിക്കുന്നതിനുള്ള സംവിധാനം
|
||||
Name[mr]=आदेश चालक
|
||||
Name[nb]=Kommandostarter
|
||||
Name[nds]=Befehldreger
|
||||
Name[ne]=आदेश रनर
|
||||
Name[nl]=Commando uitvoeren
|
||||
Name[nn]=Kommandostartar
|
||||
Name[pa]=ਕਮਾਂਡ ਰਨਰ
|
||||
Name[pl]=Uruchamianie poleceń
|
||||
Name[pt]=Execução de Comandos
|
||||
Name[pt_BR]=Executor de comando
|
||||
Name[ro]=Executor de comenzi
|
||||
Name[ru]=Запуск команд
|
||||
Name[se]=Gohččunálggaheaddji
|
||||
Name[si]=විධාන ධාවකය
|
||||
Name[sk]=Spúšťač príkazov
|
||||
Name[sl]=Zaganjalnik ukazov
|
||||
Name[sr]=Извођач наредби
|
||||
Name[sr@ijekavian]=Извођач наредби
|
||||
Name[sr@ijekavianlatin]=Izvođač naredbi
|
||||
Name[sr@latin]=Izvođač naredbi
|
||||
Name[sv]=Kör kommando
|
||||
Name[ta]=Command Runner
|
||||
Name[te]=కమాండ్ రన్నర్
|
||||
Name[tg]=Иҷрогари фармонҳо
|
||||
Name[th]=ตัวเรียกคำสั่งทำงาน
|
||||
Name[tr]=Komut Çalıştırıcı
|
||||
Name[ug]=بۇيرۇق ئىجرا قىلغۇچى
|
||||
Name[uk]=Запуск команд
|
||||
Name[vi]=Chạy lệnh
|
||||
Name[wa]=Enondeu d' colande
|
||||
Name[x-test]=xxCommand Runnerxx
|
||||
Name[zh_CN]=命令运行器
|
||||
Name[zh_TW]=命令執行者
|
||||
Type=Service
|
||||
StartupNotify=false
|
||||
OnlyShowIn=KDE;
|
||||
X-KDE-autostart-phase=1
|
|
@ -1,323 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* 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 Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "krunnerapp.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QObject>
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
#include <KAction>
|
||||
#include <KActionCollection>
|
||||
#include <KCrash>
|
||||
#include <KLocale>
|
||||
#include <KWindowSystem>
|
||||
|
||||
#include <Plasma/RunnerManager>
|
||||
#include <Plasma/AbstractRunner>
|
||||
|
||||
#include "kworkspace/kdisplaymanager.h"
|
||||
|
||||
#include "appadaptor.h"
|
||||
#include "ksystemactivitydialog.h"
|
||||
#include "interfaces/default/interface.h"
|
||||
#include "interfaces/quicksand/qs_dialog.h"
|
||||
#include "krunnersettings.h"
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#endif
|
||||
|
||||
KRunnerApp* KRunnerApp::self()
|
||||
{
|
||||
if (!kapp) {
|
||||
return new KRunnerApp();
|
||||
}
|
||||
|
||||
return qobject_cast<KRunnerApp*>(kapp);
|
||||
}
|
||||
|
||||
KRunnerApp::KRunnerApp()
|
||||
: KUniqueApplication(),
|
||||
m_interface(0),
|
||||
m_tasks(0),
|
||||
m_firstTime(true)
|
||||
{
|
||||
initialize();
|
||||
connect(this, SIGNAL(aboutToQuit()), this, SLOT(cleanUp()));
|
||||
}
|
||||
|
||||
KRunnerApp::~KRunnerApp()
|
||||
{
|
||||
}
|
||||
|
||||
void KRunnerApp::cleanUp()
|
||||
{
|
||||
disconnect(KRunnerSettings::self(), SIGNAL(configChanged()), this, SLOT(reloadConfig()));
|
||||
kDebug() << "deleting interface";
|
||||
delete m_interface;
|
||||
m_interface = 0;
|
||||
delete m_runnerManager;
|
||||
m_runnerManager = 0;
|
||||
delete m_tasks;
|
||||
m_tasks = 0;
|
||||
KGlobal::config()->sync();
|
||||
}
|
||||
|
||||
KActionCollection* KRunnerApp::actionCollection()
|
||||
{
|
||||
return m_actionCollection;
|
||||
}
|
||||
|
||||
void KRunnerApp::initialize()
|
||||
{
|
||||
setWindowIcon(KIcon(QLatin1String("system-run")));
|
||||
|
||||
setQuitOnLastWindowClosed(false);
|
||||
KCrash::setFlags(KCrash::AutoRestart | KCrash::Log);
|
||||
|
||||
connect(KRunnerSettings::self(), SIGNAL(configChanged()), this, SLOT(reloadConfig()));
|
||||
|
||||
m_runnerManager = new Plasma::RunnerManager;
|
||||
|
||||
new AppAdaptor(this);
|
||||
QDBusConnection::sessionBus().registerObject(QLatin1String("/App"), this);
|
||||
|
||||
// Global keys
|
||||
m_actionCollection = new KActionCollection(this);
|
||||
KAction* a = 0;
|
||||
|
||||
a = m_actionCollection->addAction(QLatin1String("Run Command"));
|
||||
a->setText(i18n("Run Command"));
|
||||
a->setGlobalShortcut(KShortcut(Qt::ALT+Qt::Key_F2));
|
||||
connect(a, SIGNAL(triggered(bool)), SLOT(displayOrHide()));
|
||||
|
||||
a = m_actionCollection->addAction(QLatin1String("Run Command on clipboard contents"));
|
||||
a->setText(i18n("Run Command on clipboard contents"));
|
||||
a->setGlobalShortcut(KShortcut(Qt::ALT+Qt::SHIFT+Qt::Key_F2));
|
||||
connect(a, SIGNAL(triggered(bool)), SLOT(displayWithClipboardContents()));
|
||||
|
||||
a = m_actionCollection->addAction(QLatin1String("Show System Activity"));
|
||||
a->setText(i18n("Show System Activity"));
|
||||
a->setGlobalShortcut(KShortcut(Qt::CTRL+Qt::Key_Escape));
|
||||
connect(a, SIGNAL(triggered(bool)), SLOT(showTaskManager()));
|
||||
|
||||
a = m_actionCollection->addAction(QLatin1String("Switch User"));
|
||||
a->setText(i18n("Switch User"));
|
||||
a->setGlobalShortcut(KShortcut(Qt::ALT+Qt::CTRL+Qt::Key_Insert));
|
||||
connect(a, SIGNAL(triggered(bool)), SLOT(switchUser()));
|
||||
|
||||
//Setup the interface after we have set up the actions
|
||||
switch (KRunnerSettings::interface()) {
|
||||
default:
|
||||
case KRunnerSettings::EnumInterface::CommandOriented:
|
||||
m_interface = new Interface(m_runnerManager);
|
||||
break;
|
||||
case KRunnerSettings::EnumInterface::TaskOriented:
|
||||
m_interface = new QsDialog(m_runnerManager);
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
XClassHint classHint;
|
||||
classHint.res_name = const_cast<char*>("krunner");
|
||||
classHint.res_class = const_cast<char*>("krunner");
|
||||
XSetClassHint(QX11Info::display(), m_interface->winId(), &classHint);
|
||||
#endif
|
||||
|
||||
|
||||
m_actionCollection->readSettings();
|
||||
//m_runnerManager->setAllowedRunners(QStringList() << "shell");
|
||||
m_runnerManager->reloadConfiguration(); // pre-load the runners
|
||||
|
||||
// Single runner mode actions shortcuts
|
||||
|
||||
foreach (const QString &runnerId, m_runnerManager->singleModeAdvertisedRunnerIds()) {
|
||||
a = m_actionCollection->addAction(runnerId);
|
||||
a->setText(i18nc("Run krunner restricting the search only to runner %1", "Run Command (runner \"%1\" only)",
|
||||
m_runnerManager->runnerName(runnerId)));
|
||||
a->setGlobalShortcut(KShortcut());
|
||||
connect(a, SIGNAL(triggered(bool)), SLOT(singleRunnerModeActionTriggered()));
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerApp::singleRunnerModeActionTriggered()
|
||||
{
|
||||
KAction * action = qobject_cast<KAction*>(sender());
|
||||
if (action) {
|
||||
displaySingleRunner(action->objectName());
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerApp::querySingleRunner(const QString& runnerId, const QString &term)
|
||||
{
|
||||
m_runnerManager->setSingleModeRunnerId(runnerId);
|
||||
m_runnerManager->setSingleMode(!runnerId.isEmpty());
|
||||
|
||||
if (m_runnerManager->singleMode()) {
|
||||
m_interface->display(term);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList KRunnerApp::singleModeAdvertisedRunnerIds() const
|
||||
{
|
||||
return m_runnerManager->singleModeAdvertisedRunnerIds();
|
||||
}
|
||||
|
||||
void KRunnerApp::showTaskManager()
|
||||
{
|
||||
showTaskManagerWithFilter(QString());
|
||||
}
|
||||
|
||||
void KRunnerApp::showTaskManagerWithFilter(const QString &filterText)
|
||||
{
|
||||
//kDebug() << "Launching KSysGuard...";
|
||||
if (!m_tasks) {
|
||||
m_tasks = new KSystemActivityDialog;
|
||||
connect(m_tasks, SIGNAL(finished()),
|
||||
this, SLOT(taskDialogFinished()));
|
||||
} else if ((filterText.isEmpty() || m_tasks->filterText() == filterText) &&
|
||||
KWindowSystem::activeWindow() == m_tasks->winId()) {
|
||||
m_tasks->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
m_tasks->run();
|
||||
m_tasks->setFilterText(filterText);
|
||||
}
|
||||
|
||||
void KRunnerApp::display()
|
||||
{
|
||||
m_runnerManager->setSingleMode(false);
|
||||
m_interface->display();
|
||||
}
|
||||
|
||||
void KRunnerApp::displaySingleRunner(const QString &runnerId)
|
||||
{
|
||||
m_runnerManager->setSingleModeRunnerId(runnerId);
|
||||
m_runnerManager->setSingleMode(!runnerId.isEmpty());
|
||||
m_interface->display();
|
||||
}
|
||||
|
||||
void KRunnerApp::displayOrHide()
|
||||
{
|
||||
if (!m_interface->isVisible()) {
|
||||
m_runnerManager->setSingleMode(false);
|
||||
}
|
||||
|
||||
if (m_interface->freeFloating()) {
|
||||
if (m_interface->isVisible()) {
|
||||
m_interface->hide();
|
||||
} else {
|
||||
m_interface->display();
|
||||
}
|
||||
} else if (m_interface->isActiveWindow()) {
|
||||
m_interface->hide();
|
||||
} else {
|
||||
m_interface->display();
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerApp::query(const QString &term)
|
||||
{
|
||||
m_interface->display(term);
|
||||
}
|
||||
|
||||
void KRunnerApp::displayWithClipboardContents()
|
||||
{
|
||||
QString clipboardData = QApplication::clipboard()->text(QClipboard::Selection);
|
||||
m_interface->display(clipboardData);
|
||||
}
|
||||
|
||||
void KRunnerApp::switchUser()
|
||||
{
|
||||
const KService::Ptr service = KService::serviceByStorageId(QLatin1String("plasma-runner-sessions.desktop"));
|
||||
KPluginInfo info(service);
|
||||
|
||||
if (info.isValid()) {
|
||||
SessList sessions;
|
||||
KDisplayManager dm;
|
||||
dm.localSessions(sessions);
|
||||
|
||||
if (sessions.isEmpty()) {
|
||||
// no sessions to switch between, let's just start up another session directly
|
||||
Plasma::AbstractRunner *sessionRunner = m_runnerManager->runner(info.pluginName());
|
||||
if (sessionRunner) {
|
||||
Plasma::QueryMatch switcher(sessionRunner);
|
||||
sessionRunner->run(*m_runnerManager->searchContext(), switcher);
|
||||
}
|
||||
} else {
|
||||
m_runnerManager->setSingleModeRunnerId(info.pluginName());
|
||||
m_runnerManager->setSingleMode(true);
|
||||
m_interface->display();
|
||||
//TODO: ugh, magic strings. See sessions/sessionrunner.cpp
|
||||
m_runnerManager->launchQuery(QLatin1String("SESSIONS"), info.pluginName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerApp::clearHistory()
|
||||
{
|
||||
m_interface->clearHistory();
|
||||
}
|
||||
|
||||
void KRunnerApp::taskDialogFinished()
|
||||
{
|
||||
m_tasks->deleteLater();
|
||||
m_tasks = 0;
|
||||
}
|
||||
|
||||
int KRunnerApp::newInstance()
|
||||
{
|
||||
if (m_firstTime) {
|
||||
m_firstTime = false;
|
||||
} else {
|
||||
display();
|
||||
}
|
||||
|
||||
return KUniqueApplication::newInstance();
|
||||
//return 0;
|
||||
}
|
||||
|
||||
void KRunnerApp::reloadConfig()
|
||||
{
|
||||
//Prevent Interface destructor from triggering this method
|
||||
disconnect(KRunnerSettings::self(), SIGNAL(configChanged()), this, SLOT(reloadConfig()));
|
||||
|
||||
const int interface = KRunnerSettings::interface();
|
||||
if (!qobject_cast<QsDialog*>(m_interface) &&
|
||||
interface == KRunnerSettings::EnumInterface::TaskOriented) {
|
||||
m_interface->deleteLater();
|
||||
m_interface = new QsDialog(m_runnerManager);
|
||||
} else if (!qobject_cast<Interface*>(m_interface) &&
|
||||
interface == KRunnerSettings::EnumInterface::CommandOriented) {
|
||||
m_interface->deleteLater();
|
||||
m_interface = new Interface(m_runnerManager);
|
||||
}
|
||||
|
||||
m_interface->setFreeFloating(KRunnerSettings::freeFloating());
|
||||
connect(KRunnerSettings::self(), SIGNAL(configChanged()), this, SLOT(reloadConfig()));
|
||||
display();
|
||||
}
|
||||
|
||||
#include "moc_krunnerapp.cpp"
|
|
@ -1,103 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* 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 Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KRUNNERAPP_H
|
||||
#define KRUNNERAPP_H
|
||||
|
||||
#include <kuniqueapplication.h>
|
||||
|
||||
class KActionCollection;
|
||||
class KDialog;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class RunnerManager;
|
||||
}
|
||||
|
||||
class KRunnerDialog;
|
||||
class KSystemActivityDialog;
|
||||
|
||||
class KRunnerApp : public KUniqueApplication
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.kde.krunner.App")
|
||||
|
||||
public:
|
||||
static KRunnerApp* self();
|
||||
~KRunnerApp();
|
||||
|
||||
// The action collection of the active widget
|
||||
KActionCollection* actionCollection();
|
||||
|
||||
virtual int newInstance();
|
||||
|
||||
public Q_SLOTS:
|
||||
// DBUS interface. if you change these methods, you MUST run:
|
||||
// qdbuscpp2xml -m krunnerapp.h -o dbus/org.kde.krunner.App.xml
|
||||
|
||||
/** Show taskmanager */
|
||||
Q_SCRIPTABLE void showTaskManager();
|
||||
/** Show taskmanager, filtering by the given string */
|
||||
Q_SCRIPTABLE void showTaskManagerWithFilter(const QString &filterText);
|
||||
|
||||
/** Display the interface */
|
||||
Q_SCRIPTABLE void display();
|
||||
|
||||
/** Enter single runner query mode **/
|
||||
Q_SCRIPTABLE void displaySingleRunner(const QString& runnerName);
|
||||
|
||||
/** Display the interface, using clipboard contents */
|
||||
Q_SCRIPTABLE void displayWithClipboardContents();
|
||||
|
||||
/** Display the interface */
|
||||
Q_SCRIPTABLE void query(const QString& term);
|
||||
|
||||
/** Enter single runner query mode **/
|
||||
Q_SCRIPTABLE void querySingleRunner(const QString& runnerName, const QString &term);
|
||||
|
||||
/** Switch user */
|
||||
Q_SCRIPTABLE void switchUser();
|
||||
|
||||
/** Clear the search history */
|
||||
Q_SCRIPTABLE void clearHistory();
|
||||
|
||||
Q_SCRIPTABLE QStringList singleModeAdvertisedRunnerIds() const;
|
||||
|
||||
private slots:
|
||||
/**
|
||||
* Called when the task dialog emits its finished() signal
|
||||
*/
|
||||
void taskDialogFinished();
|
||||
void reloadConfig();
|
||||
void cleanUp();
|
||||
void displayOrHide();
|
||||
void singleRunnerModeActionTriggered();
|
||||
|
||||
private:
|
||||
KRunnerApp();
|
||||
void initialize();
|
||||
|
||||
Plasma::RunnerManager *m_runnerManager;
|
||||
KActionCollection *m_actionCollection;
|
||||
KRunnerDialog *m_interface;
|
||||
KSystemActivityDialog *m_tasks;
|
||||
bool m_firstTime;
|
||||
};
|
||||
|
||||
#endif /* KRUNNERAPP_H */
|
||||
|
|
@ -1,542 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* 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 Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "krunnerdialog.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QBitmap>
|
||||
#include <QTimer>
|
||||
#include <QDesktopWidget>
|
||||
#ifdef Q_WS_X11
|
||||
#include <QtGui/qx11info_x11.h>
|
||||
#endif
|
||||
|
||||
#include <KDebug>
|
||||
#include <KWindowSystem>
|
||||
#include <KPluginInfo>
|
||||
#ifdef Q_WS_X11
|
||||
#include <NETRootInfo>
|
||||
#endif
|
||||
|
||||
#include "kworkspace/kdisplaymanager.h"
|
||||
|
||||
#include <Plasma/AbstractRunner>
|
||||
#include <Plasma/FrameSvg>
|
||||
#include <Plasma/RunnerManager>
|
||||
#include <Plasma/Theme>
|
||||
#include <Plasma/WindowEffects>
|
||||
|
||||
#include "configdialog.h"
|
||||
#include "krunnerapp.h"
|
||||
#include "krunnersettings.h"
|
||||
#include "panelshadows.h"
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
#include <X11/Xlib.h>
|
||||
#endif
|
||||
|
||||
KRunnerDialog::KRunnerDialog(Plasma::RunnerManager *runnerManager, QWidget *parent, Qt::WindowFlags f)
|
||||
: QWidget(parent, f),
|
||||
m_runnerManager(runnerManager),
|
||||
m_configWidget(0),
|
||||
m_background(new Plasma::FrameSvg(this)),
|
||||
m_shownOnScreen(-1),
|
||||
m_offset(.5),
|
||||
m_floating(!KRunnerSettings::freeFloating()),
|
||||
m_resizing(false),
|
||||
m_rightResize(false),
|
||||
m_vertResize(false),
|
||||
m_runningTimer(false),
|
||||
m_desktopWidget(qApp->desktop())
|
||||
{
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
setMouseTracking(true);
|
||||
//setButtons(0);
|
||||
setWindowTitle(i18nc("@title:window", "Run Command"));
|
||||
setWindowIcon(KIcon(QLatin1String("system-run")));
|
||||
|
||||
QPalette pal = palette();
|
||||
pal.setColor(backgroundRole(), Qt::transparent);
|
||||
setPalette(pal);
|
||||
|
||||
m_iconSvg = new Plasma::Svg(this);
|
||||
m_iconSvg->setImagePath(QLatin1String("widgets/configuration-icons"));
|
||||
|
||||
connect(m_background, SIGNAL(repaintNeeded()), this, SLOT(themeUpdated()));
|
||||
|
||||
connect(m_desktopWidget, SIGNAL(resized(int)), this, SLOT(screenGeometryChanged(int)));
|
||||
connect(m_desktopWidget, SIGNAL(screenCountChanged(int)), this, SLOT(screenGeometryChanged(int)));
|
||||
|
||||
connect(KWindowSystem::self(), SIGNAL(workAreaChanged()), this, SLOT(resetScreenPos()));
|
||||
connect(KWindowSystem::self(), SIGNAL(compositingChanged(bool)), this, SLOT(compositingChanged(bool)));
|
||||
|
||||
setFreeFloating(KRunnerSettings::freeFloating());
|
||||
}
|
||||
|
||||
KRunnerDialog::~KRunnerDialog()
|
||||
{
|
||||
//kDebug( )<< "!!!!!!!!!! deleting" << m_floating << m_screenPos.count();
|
||||
if (!m_floating) {
|
||||
KConfigGroup cg(KGlobal::config(), "EdgePositions");
|
||||
cg.writeEntry(QLatin1String("Offset"), m_offset);
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerDialog::screenResized(int screen)
|
||||
{
|
||||
if (isVisible() && screen == m_shownOnScreen) {
|
||||
positionOnScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerDialog::screenGeometryChanged(int screenCount)
|
||||
{
|
||||
if (isVisible()) {
|
||||
positionOnScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerDialog::resetScreenPos()
|
||||
{
|
||||
if (isVisible() && !m_floating) {
|
||||
positionOnScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerDialog::positionOnScreen()
|
||||
{
|
||||
if (m_desktopWidget->screenCount() < 2) {
|
||||
m_shownOnScreen = m_desktopWidget->primaryScreen();
|
||||
} else if (isVisible()) {
|
||||
m_shownOnScreen = m_desktopWidget->screenNumber(geometry().center());
|
||||
} else {
|
||||
m_shownOnScreen = m_desktopWidget->screenNumber(QCursor::pos());
|
||||
}
|
||||
|
||||
const QRect r = m_desktopWidget->screenGeometry(m_shownOnScreen);
|
||||
|
||||
if (m_floating && !m_customPos.isNull()) {
|
||||
int x = qBound(r.left(), m_customPos.x(), r.right() - width());
|
||||
int y = qBound(r.top(), m_customPos.y(), r.bottom() - height());
|
||||
move(x, y);
|
||||
show();
|
||||
return;
|
||||
}
|
||||
|
||||
const int w = width();
|
||||
int x = r.left() + (r.width() * m_offset) - (w / 2);
|
||||
|
||||
int y = r.top();
|
||||
if (m_floating) {
|
||||
y += r.height() / 3;
|
||||
}
|
||||
|
||||
x = qBound(r.left(), x, r.right() - width());
|
||||
y = qBound(r.top(), y, r.bottom() - height());
|
||||
|
||||
move(x, y);
|
||||
|
||||
if (!m_floating) {
|
||||
checkBorders(r);
|
||||
}
|
||||
|
||||
show();
|
||||
|
||||
if (m_floating) {
|
||||
KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop());
|
||||
//Turn the sliding effect off
|
||||
Plasma::WindowEffects::slideWindow(this, Plasma::Floating);
|
||||
} else {
|
||||
KWindowSystem::setOnAllDesktops(winId(), true);
|
||||
Plasma::WindowEffects::slideWindow(this, Plasma::TopEdge);
|
||||
}
|
||||
|
||||
KWindowSystem::forceActiveWindow(winId());
|
||||
//kDebug() << "moving to" << m_screenPos[screen];
|
||||
}
|
||||
|
||||
void KRunnerDialog::moveEvent(QMoveEvent *)
|
||||
{
|
||||
if (m_floating) {
|
||||
m_customPos = pos();
|
||||
} else {
|
||||
const QRect screen = m_desktopWidget->screenGeometry(m_shownOnScreen);
|
||||
m_offset = qRound((geometry().center().x() - screen.x()) / qreal(screen.width()) * 100) / 100.0;
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerDialog::setFreeFloating(bool floating)
|
||||
{
|
||||
if (m_floating == floating) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_floating = floating;
|
||||
m_shownOnScreen = -1;
|
||||
unsetCursor();
|
||||
updatePresentation();
|
||||
}
|
||||
|
||||
void KRunnerDialog::updatePresentation()
|
||||
{
|
||||
if (m_floating) {
|
||||
KWindowSystem::setType(winId(), NET::Normal);
|
||||
|
||||
m_background->setImagePath(QLatin1String("dialogs/krunner"));
|
||||
m_background->setElementPrefix(QString());
|
||||
|
||||
themeUpdated();
|
||||
} else {
|
||||
if (KWindowSystem::compositingActive()) {
|
||||
m_background->setImagePath(QLatin1String("widgets/translucentbackground"));
|
||||
}
|
||||
if (!m_background->isValid()) {
|
||||
m_background->setImagePath(QLatin1String("widgets/panel-background"));
|
||||
}
|
||||
m_background->resizeFrame(size());
|
||||
m_background->setElementPrefix("north-mini");
|
||||
// load the positions for each screen from our config
|
||||
KConfigGroup cg(KGlobal::config(), "EdgePositions");
|
||||
m_offset = cg.readEntry(QLatin1String("Offset"), m_offset);
|
||||
const QRect r = m_desktopWidget->screenGeometry(m_shownOnScreen);
|
||||
checkBorders(r);
|
||||
KWindowSystem::setType(winId(), NET::Dock);
|
||||
}
|
||||
|
||||
if (isVisible()) {
|
||||
positionOnScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerDialog::compositingChanged(bool)
|
||||
{
|
||||
updatePresentation();
|
||||
updateMask();
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
bool KRunnerDialog::freeFloating() const
|
||||
{
|
||||
return m_floating;
|
||||
}
|
||||
|
||||
KRunnerDialog::ResizeMode KRunnerDialog::manualResizing() const
|
||||
{
|
||||
if (!m_resizing) {
|
||||
return NotResizing;
|
||||
} else if (m_vertResize) {
|
||||
return VerticalResizing;
|
||||
} else {
|
||||
return HorizontalResizing;
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerDialog::setStaticQueryMode(bool staticQuery)
|
||||
{
|
||||
Q_UNUSED(staticQuery)
|
||||
}
|
||||
|
||||
void KRunnerDialog::toggleConfigDialog()
|
||||
{
|
||||
if (m_configWidget) {
|
||||
delete m_configWidget;
|
||||
m_configWidget = 0;
|
||||
|
||||
if (!m_floating) {
|
||||
KWindowSystem::setType(winId(), NET::Dock);
|
||||
}
|
||||
} else {
|
||||
m_configWidget = new KRunnerConfigWidget(m_runnerManager, this);
|
||||
connect(m_configWidget, SIGNAL(finished()), this, SLOT(configCompleted()));
|
||||
setConfigWidget(m_configWidget);
|
||||
KWindowSystem::setType(winId(), NET::Normal);
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerDialog::configCompleted()
|
||||
{
|
||||
if (m_configWidget) {
|
||||
m_configWidget->deleteLater();
|
||||
m_configWidget = 0;
|
||||
}
|
||||
|
||||
if (!m_floating) {
|
||||
KWindowSystem::setType(winId(), NET::Dock);
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerDialog::themeUpdated()
|
||||
{
|
||||
if (m_floating) {
|
||||
// recalc the contents margins
|
||||
m_background->blockSignals(true);
|
||||
if (KWindowSystem::compositingActive()) {
|
||||
m_background->setEnabledBorders(Plasma::FrameSvg::NoBorder);
|
||||
} else {
|
||||
m_background->setEnabledBorders(Plasma::FrameSvg::AllBorders);
|
||||
}
|
||||
m_background->blockSignals(false);
|
||||
}
|
||||
|
||||
m_leftBorderWidth = qMax(0, int(m_background->marginSize(Plasma::LeftMargin)));
|
||||
m_rightBorderWidth = qMax(0, int(m_background->marginSize(Plasma::RightMargin)));
|
||||
m_bottomBorderHeight = qMax(0, int(m_background->marginSize(Plasma::BottomMargin)));
|
||||
// the -1 in the non-floating case is not optimal, but it gives it a bit of a "more snug to the
|
||||
// top" feel; best would be if we could tell exactly where the edge/shadow of the frame svg was
|
||||
// but this works nicely
|
||||
m_topBorderHeight = m_floating ? qMax(0, int(m_background->marginSize(Plasma::TopMargin)))
|
||||
: Plasma::Theme::defaultTheme()->windowTranslucencyEnabled()
|
||||
? qMax(1, m_bottomBorderHeight / 2)
|
||||
: qMax(1, m_bottomBorderHeight - 1);
|
||||
|
||||
kDebug() << m_leftBorderWidth << m_topBorderHeight << m_rightBorderWidth << m_bottomBorderHeight;
|
||||
// the +1 gives us the extra mouseMoveEvent needed to always reset the resize cursor
|
||||
setContentsMargins(m_leftBorderWidth + 1, m_topBorderHeight, m_rightBorderWidth + 1, m_bottomBorderHeight + 1);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void KRunnerDialog::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QPainter p(this);
|
||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
p.setClipRect(e->rect());
|
||||
//kDebug() << "clip rect set to: " << e->rect();
|
||||
|
||||
m_background->paintFrame(&p);
|
||||
}
|
||||
|
||||
void KRunnerDialog::showEvent(QShowEvent *)
|
||||
{
|
||||
unsigned long state = NET::SkipTaskbar | NET::KeepAbove;
|
||||
if (m_floating) {
|
||||
KWindowSystem::clearState(winId(), state);
|
||||
} else {
|
||||
KWindowSystem::setState(winId(), state);
|
||||
}
|
||||
m_runnerManager->setupMatchSession();
|
||||
}
|
||||
|
||||
void KRunnerDialog::hideEvent(QHideEvent *)
|
||||
{
|
||||
// We delay the call to matchSessionComplete until next event cycle
|
||||
// This is necessary since we might hide the dialog right before running
|
||||
// a match, and the runner might still need to be prepped to
|
||||
// succesfully run a match
|
||||
QTimer::singleShot(0, m_runnerManager, SLOT(matchSessionComplete()));
|
||||
delete m_configWidget;
|
||||
m_configWidget = 0;
|
||||
}
|
||||
|
||||
void KRunnerDialog::updateMask()
|
||||
{
|
||||
// Enable the mask only when compositing is disabled;
|
||||
// As this operation is quite slow, it would be nice to find some
|
||||
// way to workaround it for no-compositing users.
|
||||
|
||||
if (KWindowSystem::compositingActive()) {
|
||||
clearMask();
|
||||
} else {
|
||||
setMask(m_background->mask());
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerDialog::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
m_background->resizeFrame(e->size());
|
||||
|
||||
bool maskDirty = true;
|
||||
if (m_resizing && !m_vertResize) {
|
||||
const QRect r = m_desktopWidget->screenGeometry(m_shownOnScreen);
|
||||
//kDebug() << "if" << x() << ">" << r.left() << "&&" << r.right() << ">" << (x() + width());
|
||||
const Plasma::FrameSvg::EnabledBorders borders = m_background->enabledBorders();
|
||||
if (borders & Plasma::FrameSvg::LeftBorder) {
|
||||
const int dx = x() + (e->oldSize().width() - width()) / 2 ;
|
||||
const int dy = (m_floating ? pos().y() : r.top());
|
||||
move(qBound(r.left(), dx, r.right() - width() + 1), dy);
|
||||
maskDirty = m_floating || !checkBorders(r);
|
||||
}
|
||||
}
|
||||
|
||||
if (maskDirty) {
|
||||
updateMask();
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerDialog::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
m_lastPressPos = e->globalPos();
|
||||
|
||||
const bool leftResize = e->x() < qMax(5, m_leftBorderWidth);
|
||||
m_rightResize = e->x() > width() - qMax(5, m_rightBorderWidth);
|
||||
m_vertResize = e->y() > height() - qMax(5, m_bottomBorderHeight);
|
||||
kWarning() << "right:" << m_rightResize << "left:" << leftResize << "vert:" << m_vertResize;
|
||||
if (m_rightResize || m_vertResize || leftResize) {
|
||||
// let's do a resize! :)
|
||||
grabMouse();
|
||||
m_resizing = true;
|
||||
} else if (m_floating) {
|
||||
#ifdef Q_WS_X11
|
||||
m_lastPressPos = QPoint();
|
||||
// We have to release the mouse grab before initiating the move operation.
|
||||
// Ideally we would call releaseMouse() to do this, but when we only have an
|
||||
// implicit passive grab, Qt is unaware of it, and will refuse to release it.
|
||||
XUngrabPointer(x11Info().display(), CurrentTime);
|
||||
|
||||
// Ask the window manager to start an interactive move operation.
|
||||
NETRootInfo rootInfo(x11Info().display(), NET::WMMoveResize);
|
||||
rootInfo.moveResizeRequest(winId(), e->globalX(), e->globalY(), NET::Move);
|
||||
#endif
|
||||
}
|
||||
e->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerDialog::mouseReleaseEvent(QMouseEvent *)
|
||||
{
|
||||
if (!m_lastPressPos.isNull()) {
|
||||
releaseMouse();
|
||||
unsetCursor();
|
||||
m_lastPressPos = QPoint();
|
||||
m_resizing = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool KRunnerDialog::checkBorders(const QRect &screenGeom)
|
||||
{
|
||||
Q_ASSERT(!m_floating);
|
||||
Plasma::FrameSvg::EnabledBorders borders = Plasma::FrameSvg::BottomBorder;
|
||||
|
||||
if (x() > screenGeom.left()) {
|
||||
borders |= Plasma::FrameSvg::LeftBorder;
|
||||
}
|
||||
|
||||
if (x() + width() < screenGeom.right()) {
|
||||
borders |= Plasma::FrameSvg::RightBorder;
|
||||
}
|
||||
|
||||
if (borders != m_background->enabledBorders()) {
|
||||
m_background->setEnabledBorders(borders);
|
||||
themeUpdated();
|
||||
updateMask();
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void KRunnerDialog::leaveEvent(QEvent *)
|
||||
{
|
||||
unsetCursor();
|
||||
}
|
||||
|
||||
void KRunnerDialog::mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
//kDebug() << e->x() << m_leftBorderWidth << width() << m_rightBorderWidth;
|
||||
if (m_lastPressPos.isNull()) {
|
||||
// not press positiong, so we aren't going to resize or move.
|
||||
checkCursor(e->pos());
|
||||
} else if (m_resizing) {
|
||||
// resizing
|
||||
if (m_vertResize) {
|
||||
const int deltaY = e->globalY() - m_lastPressPos.y();
|
||||
resize(width(), qMax(80, height() + deltaY));
|
||||
m_lastPressPos = e->globalPos();
|
||||
} else {
|
||||
const QRect r = m_desktopWidget->availableGeometry(m_shownOnScreen);
|
||||
const int deltaX = (m_rightResize ? -1 : 1) * (m_lastPressPos.x() - e->globalX());
|
||||
int newWidth = width() + deltaX;
|
||||
|
||||
// don't let it grow beyond the opposite screen edge
|
||||
if (m_rightResize) {
|
||||
if (m_leftBorderWidth > 0) {
|
||||
newWidth += qMin(deltaX, x() - r.left());
|
||||
}
|
||||
} else if (m_rightBorderWidth > 0) {
|
||||
newWidth += qMin(deltaX, r.right() - (x() + width() - 1));
|
||||
} else if (newWidth > minimumWidth() && newWidth < width()) {
|
||||
move(r.right() - newWidth + 1, y());
|
||||
}
|
||||
|
||||
if (newWidth > minimumWidth()) {
|
||||
resize(newWidth, height());
|
||||
m_lastPressPos = e->globalPos();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// moving
|
||||
const QRect r = m_desktopWidget->availableGeometry(m_shownOnScreen);
|
||||
int newX = qBound(r.left(), x() - (m_lastPressPos.x() - e->globalX()), r.right() - width() + 1);
|
||||
if (abs(r.center().x() - (newX + (width() / 2))) < 20) {
|
||||
newX = r.center().x() - (width() / 2);
|
||||
} else {
|
||||
m_lastPressPos = e->globalPos();
|
||||
}
|
||||
|
||||
move(newX, y());
|
||||
checkBorders(r);
|
||||
}
|
||||
}
|
||||
|
||||
void KRunnerDialog::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
killTimer(event->timerId());
|
||||
if (checkCursor(mapFromGlobal(QCursor::pos()))) {
|
||||
m_runningTimer = true;
|
||||
startTimer(100);
|
||||
} else {
|
||||
m_runningTimer = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool KRunnerDialog::checkCursor(const QPoint &pos)
|
||||
{
|
||||
//Plasma::FrameSvg borders = m_background->enabledBoders();
|
||||
if ((m_leftBorderWidth > 0 && pos.x() < qMax(5, m_leftBorderWidth)) ||
|
||||
(m_rightBorderWidth > 0 && pos.x() > width() - qMax(5, m_rightBorderWidth))) {
|
||||
if (cursor().shape() != Qt::SizeHorCursor) {
|
||||
setCursor(Qt::SizeHorCursor);
|
||||
if (!m_runningTimer) {
|
||||
m_runningTimer = true;
|
||||
startTimer(100);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if ((pos.y() > height() - qMax(5, m_bottomBorderHeight)) && (pos.y() < height())) {
|
||||
if (cursor().shape() != Qt::SizeVerCursor) {
|
||||
setCursor(Qt::SizeVerCursor);
|
||||
if (!m_runningTimer) {
|
||||
m_runningTimer = true;
|
||||
startTimer(100);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
unsetCursor();
|
||||
return false;
|
||||
}
|
||||
|
||||
#include "moc_krunnerdialog.cpp"
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* 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 Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KRUNNERDIALOG_H
|
||||
#define KRUNNERDIALOG_H
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <KDialog>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class RunnerManager;
|
||||
class FrameSvg;
|
||||
class Svg;
|
||||
}
|
||||
|
||||
class KRunnerConfigWidget;
|
||||
|
||||
class KRunnerDialog : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit KRunnerDialog(Plasma::RunnerManager *manager, QWidget *parent = 0,
|
||||
Qt::WindowFlags f = Qt::Dialog | Qt::FramelessWindowHint);
|
||||
virtual ~KRunnerDialog();
|
||||
|
||||
void setFreeFloating(bool floating);
|
||||
bool freeFloating() const;
|
||||
|
||||
enum ResizeMode { NotResizing = 0, VerticalResizing, HorizontalResizing };
|
||||
ResizeMode manualResizing() const;
|
||||
virtual void setConfigWidget(QWidget *w) = 0;
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void display(const QString &term = QString()) = 0;
|
||||
virtual void clearHistory() = 0;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void leaveEvent(QEvent *e);
|
||||
void showEvent(QShowEvent *);
|
||||
void hideEvent(QHideEvent *);
|
||||
void moveEvent(QMoveEvent *);
|
||||
|
||||
void positionOnScreen();
|
||||
virtual void setStaticQueryMode(bool staticQuery);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void toggleConfigDialog();
|
||||
void timerEvent(QTimerEvent *event);
|
||||
|
||||
/**
|
||||
* React to configuration being done
|
||||
*/
|
||||
void configCompleted();
|
||||
|
||||
private:
|
||||
void updatePresentation();
|
||||
bool checkBorders(const QRect &screenGeom);
|
||||
bool checkCursor(const QPoint &pos);
|
||||
void updateMask();
|
||||
void paintBackground(QPainter* painter, const QRect &exposedRect);
|
||||
|
||||
private Q_SLOTS:
|
||||
/**
|
||||
* React to theme changes
|
||||
*/
|
||||
void themeUpdated();
|
||||
|
||||
/**
|
||||
* React to screen changes
|
||||
*/
|
||||
void screenResized(int screen);
|
||||
void screenGeometryChanged(int screenCount);
|
||||
void resetScreenPos();
|
||||
|
||||
void compositingChanged(bool);
|
||||
|
||||
protected:
|
||||
Plasma::Svg *m_iconSvg;
|
||||
Plasma::RunnerManager *m_runnerManager;
|
||||
|
||||
private:
|
||||
KRunnerConfigWidget *m_configWidget;
|
||||
Plasma::FrameSvg *m_background;
|
||||
QPixmap *m_cachedBackground;
|
||||
QPoint m_lastPressPos;
|
||||
QPoint m_customPos;
|
||||
int m_topBorderHeight;
|
||||
int m_leftBorderWidth;
|
||||
int m_rightBorderWidth;
|
||||
int m_bottomBorderHeight;
|
||||
int m_shownOnScreen;
|
||||
qreal m_offset;
|
||||
bool m_floating : 1;
|
||||
bool m_resizing : 1;
|
||||
bool m_rightResize : 1;
|
||||
bool m_vertResize : 1;
|
||||
bool m_runningTimer : 1;
|
||||
QDesktopWidget *m_desktopWidget;
|
||||
QString m_singleRunnerId;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2010 John Tapsell <johnflux@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* 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 Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "ksystemactivitydialog.h"
|
||||
|
||||
#include <QAbstractScrollArea>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QLineEdit>
|
||||
#include <QLayout>
|
||||
#include <QString>
|
||||
#include <QAction>
|
||||
#include <QTreeView>
|
||||
|
||||
#include <KConfigGroup>
|
||||
#include <KGlobal>
|
||||
#include <KWindowSystem>
|
||||
|
||||
#include "krunnersettings.h"
|
||||
|
||||
KSystemActivityDialog::KSystemActivityDialog(QWidget *parent)
|
||||
: KDialog(parent), m_processList(0)
|
||||
{
|
||||
setWindowTitle(i18n("System Activity"));
|
||||
setWindowIcon(KIcon(QLatin1String( "utilities-system-monitor" )));
|
||||
setButtons(0);
|
||||
setMainWidget(&m_processList);
|
||||
setSizeGripEnabled(true);
|
||||
(void)minimumSizeHint(); //Force the dialog to be laid out now
|
||||
layout()->setContentsMargins(0,0,0,0);
|
||||
m_processList.treeView()->setCornerWidget(new QWidget);
|
||||
|
||||
// Since we kinda act like an application more than just a Window, map the usual ctrl+Q shortcut to close as well
|
||||
QAction *closeWindow = new QAction(this);
|
||||
closeWindow->setShortcut(QKeySequence::Quit);
|
||||
connect(closeWindow, SIGNAL(triggered(bool)), this, SLOT(accept()));
|
||||
addAction(closeWindow);
|
||||
|
||||
setInitialSize(QSize(650, 420));
|
||||
KConfigGroup cg = KGlobal::config()->group("TaskDialog");
|
||||
restoreDialogSize(cg);
|
||||
|
||||
m_processList.loadSettings(cg);
|
||||
// Since we default to forcing the window to be KeepAbove, if the user turns this off, remember this
|
||||
const bool keepAbove = KRunnerSettings::keepTaskDialogAbove();
|
||||
if (keepAbove) {
|
||||
KWindowSystem::setState(winId(), NET::KeepAbove );
|
||||
}
|
||||
}
|
||||
|
||||
void KSystemActivityDialog::run()
|
||||
{
|
||||
show();
|
||||
raise();
|
||||
KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop());
|
||||
KWindowSystem::forceActiveWindow(winId());
|
||||
}
|
||||
|
||||
void KSystemActivityDialog::setFilterText(const QString &filterText)
|
||||
{
|
||||
m_processList.filterLineEdit()->setText(filterText);
|
||||
m_processList.filterLineEdit()->setFocus();
|
||||
}
|
||||
|
||||
QString KSystemActivityDialog::filterText() const
|
||||
{
|
||||
return m_processList.filterLineEdit()->text();
|
||||
}
|
||||
|
||||
void KSystemActivityDialog::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
saveDialogSettings();
|
||||
event->accept();
|
||||
}
|
||||
|
||||
|
||||
void KSystemActivityDialog::reject ()
|
||||
{
|
||||
saveDialogSettings();
|
||||
QDialog::reject();
|
||||
}
|
||||
|
||||
void KSystemActivityDialog::saveDialogSettings()
|
||||
{
|
||||
//When the user closes the dialog, save the position and the KeepAbove state
|
||||
KConfigGroup cg = KGlobal::config()->group("TaskDialog");
|
||||
saveDialogSize(cg);
|
||||
m_processList.saveSettings(cg);
|
||||
|
||||
// Since we default to forcing the window to be KeepAbove, if the user turns this off, remember this
|
||||
bool keepAbove = KWindowSystem::windowInfo(winId(), NET::WMState).hasState(NET::KeepAbove);
|
||||
KRunnerSettings::setKeepTaskDialogAbove(keepAbove);
|
||||
KGlobal::config()->sync();
|
||||
}
|
||||
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2010 John Tapsell <johnflux@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* 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 Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KSYSTEMACTIVITYDIALOG__H
|
||||
#define KSYSTEMACTIVITYDIALOG__H
|
||||
|
||||
|
||||
#include <KDialog>
|
||||
|
||||
#include "processui/ksysguardprocesslist.h"
|
||||
|
||||
/** This creates a simple dialog box with a KSysguardProcessList
|
||||
*
|
||||
* It remembers the size and position of the dialog, and sets
|
||||
* the dialog to always be over the other windows
|
||||
*/
|
||||
class KSystemActivityDialog : public KDialog
|
||||
{
|
||||
public:
|
||||
KSystemActivityDialog(QWidget *parent = NULL);
|
||||
|
||||
/** Show the dialog and set the focus
|
||||
*
|
||||
* This can be called even when the dialog is already showing to bring it
|
||||
* to the front again and move it to the current desktop etc.
|
||||
*/
|
||||
void run();
|
||||
|
||||
/** Set the text in the filter line in the process list widget */
|
||||
void setFilterText(const QString &filterText);
|
||||
QString filterText() const;
|
||||
|
||||
/** Save the settings if the user presses the ESC key */
|
||||
virtual void reject();
|
||||
|
||||
protected:
|
||||
/** Save the settings if the user clicks (x) button on the window */
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
private:
|
||||
void saveDialogSettings();
|
||||
|
||||
KSysGuardProcessList m_processList;
|
||||
};
|
||||
|
||||
#endif // KSYSTEMACTIVITYDIALOG__H
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright (C) 2006 Zack Rusin <zack@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* 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 Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <KAboutData>
|
||||
#include <KCmdLineArgs>
|
||||
#include <kdebug.h>
|
||||
#include <kdeversion.h>
|
||||
#include <KLocale>
|
||||
#include <KGlobal>
|
||||
#include <config-workspace.h>
|
||||
|
||||
#include "krunnerapp.h"
|
||||
|
||||
static const char description[] = I18N_NOOP( "KDE run command interface" );
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
KAboutData aboutData( "krunner", 0, ki18n( "Run Command Interface" ),
|
||||
KDE_VERSION_STRING, ki18n(description), KAboutData::License_GPL,
|
||||
ki18n("(c) 2006, Aaron Seigo") );
|
||||
aboutData.addAuthor( ki18n("Aaron J. Seigo"),
|
||||
ki18n( "Author and maintainer" ),
|
||||
"aseigo@kde.org" );
|
||||
|
||||
KCmdLineArgs::init(argc, argv, &aboutData);
|
||||
if (!KUniqueApplication::start()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
KRunnerApp *app = KRunnerApp::self();
|
||||
KGlobal::locale()->insertCatalog(QLatin1String( "processui" ));
|
||||
KGlobal::locale()->insertCatalog(QLatin1String( "libplasma" ));
|
||||
app->disableSessionManagement(); // autostarted
|
||||
int rc = app->exec();
|
||||
delete app;
|
||||
return rc;
|
||||
}
|
||||
|
|
@ -26,8 +26,6 @@ qt4_add_dbus_adaptor(libkickoff_SRCS core/org.kde.kickoff.recent.xml core/recent
|
|||
|
||||
set(screensaver_xml ${CMAKE_SOURCE_DIR}/kscreensaver/org.freedesktop.ScreenSaver.xml)
|
||||
QT4_ADD_DBUS_INTERFACE(libkickoff_SRCS ${screensaver_xml} screensaver_interface)
|
||||
set(krunner_xml ${CMAKE_SOURCE_DIR}/krunner/dbus/org.kde.krunner.App.xml)
|
||||
QT4_ADD_DBUS_INTERFACE(libkickoff_SRCS ${krunner_xml} krunner_interface)
|
||||
set(ksmserver_xml ${CMAKE_SOURCE_DIR}/ksmserver/org.kde.KSMServerInterface.xml)
|
||||
QT4_ADD_DBUS_INTERFACE(libkickoff_SRCS ${ksmserver_xml} ksmserver_interface)
|
||||
|
||||
|
|
|
@ -119,6 +119,8 @@ void LauncherApplet::init()
|
|||
d->actions.append(d->switcher);
|
||||
connect(d->switcher, SIGNAL(triggered(bool)), this, SLOT(switchMenuStyle()));
|
||||
|
||||
setGlobalShortcut(KShortcut(Qt::ALT+Qt::Key_F2));
|
||||
|
||||
configChanged();
|
||||
Plasma::ToolTipManager::self()->registerWidget(this);
|
||||
}
|
||||
|
|
|
@ -32,13 +32,13 @@
|
|||
#include <Solid/PowerManagement>
|
||||
|
||||
// KDE Base
|
||||
#include <kworkspace/kworkspace.h>
|
||||
#include "kworkspace/kworkspace.h"
|
||||
#include "kworkspace/kdisplaymanager.h"
|
||||
|
||||
// Local
|
||||
#include "core/recentapplications.h"
|
||||
|
||||
// DBus
|
||||
#include "krunner_interface.h"
|
||||
#include "screensaver_interface.h"
|
||||
#include "ksmserver_interface.h"
|
||||
#include <QtDBus/QDBusConnection>
|
||||
|
@ -106,22 +106,11 @@ bool LeaveItemHandler::openUrl(const KUrl& url)
|
|||
// decouple dbus call, otherwise we'll run into a dead-lock
|
||||
QTimer::singleShot(0, this, SLOT(suspendHybrid()));
|
||||
return true;
|
||||
} else if (m_logoutAction == "run") {
|
||||
// decouple dbus call, otherwise we'll run into a dead-lock
|
||||
QTimer::singleShot(0, this, SLOT(runCommand()));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void LeaveItemHandler::runCommand()
|
||||
{
|
||||
QString interface("org.kde.krunner");
|
||||
org::kde::krunner::App krunner(interface, "/App", QDBusConnection::sessionBus());
|
||||
krunner.display();
|
||||
}
|
||||
|
||||
void LeaveItemHandler::logout()
|
||||
{
|
||||
KWorkSpace::ShutdownConfirm confirm = KWorkSpace::ShutdownConfirmDefault;
|
||||
|
@ -151,9 +140,12 @@ void LeaveItemHandler::lock()
|
|||
|
||||
void LeaveItemHandler::switchUser()
|
||||
{
|
||||
QString interface("org.kde.krunner");
|
||||
org::kde::krunner::App krunner(interface, "/App", QDBusConnection::sessionBus());
|
||||
krunner.switchUser();
|
||||
QDBusInterface saveriface(
|
||||
"org.freedesktop.ScreenSaver", "/ScreenSaver", "org.freedesktop.ScreenSaver"
|
||||
);
|
||||
saveriface.call("Lock");
|
||||
KDisplayManager dm;
|
||||
dm.newSession();
|
||||
}
|
||||
|
||||
void LeaveItemHandler::saveSession()
|
||||
|
|
|
@ -40,7 +40,6 @@ public:
|
|||
virtual bool openUrl(const KUrl& url);
|
||||
|
||||
private Q_SLOTS:
|
||||
void runCommand();
|
||||
void logout();
|
||||
void lock();
|
||||
void switchUser();
|
||||
|
|
|
@ -156,17 +156,14 @@ int SystemModel::rowCount(const QModelIndex &parent) const
|
|||
return LAST_ROW + 1;
|
||||
} else if (!parent.parent().isValid()) {
|
||||
switch (parent.row()) {
|
||||
case APPLICATIONS_ROW:
|
||||
return d->appsList.size() + 1;
|
||||
break;
|
||||
case BOOKMARKS_ROW:
|
||||
return d->placesModel->rowCount();
|
||||
break;
|
||||
case REMOVABLE_ROW:
|
||||
return d->placesModel->rowCount();
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
case APPLICATIONS_ROW:
|
||||
return d->appsList.size() + 1;
|
||||
case BOOKMARKS_ROW:
|
||||
return d->placesModel->rowCount();
|
||||
case REMOVABLE_ROW:
|
||||
return d->placesModel->rowCount();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,19 +193,8 @@ QVariant SystemModel::data(const QModelIndex &index, int role) const
|
|||
if (d->appsList.count() < index.row()) {
|
||||
return QVariant();
|
||||
} else if (d->appsList.count() == index.row()) {
|
||||
// "Run Command"
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return i18n("Run Command...");
|
||||
case Qt::DecorationRole:
|
||||
return KIcon("system-run");
|
||||
case SubTitleRole:
|
||||
return i18n("Run a command or a search query");
|
||||
case UrlRole:
|
||||
return "run:/";
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
// used to be "Run Command"
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
KService::Ptr service = d->appsList[index.row()];
|
||||
|
|
|
@ -36,9 +36,6 @@
|
|||
#include "core/models.h"
|
||||
#include "core/urlitemlauncher.h"
|
||||
|
||||
// DBus
|
||||
#include "krunner_interface.h"
|
||||
|
||||
using namespace Kickoff;
|
||||
|
||||
class HandlerInfo
|
||||
|
@ -53,14 +50,7 @@ class GenericItemHandler : public UrlItemHandler
|
|||
{
|
||||
public:
|
||||
virtual bool openUrl(const KUrl& url) {
|
||||
if (url.protocol() == "run") {
|
||||
QString interface("org.kde.krunner");
|
||||
org::kde::krunner::App krunner(interface, "/App", QDBusConnection::sessionBus());
|
||||
krunner.display();
|
||||
return true;
|
||||
}
|
||||
|
||||
new KRun(url, 0);
|
||||
new KRun(url, nullptr);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -196,7 +196,6 @@ public:
|
|||
case RecentlyUsedApplications: return i18n("Recently Used Applications");
|
||||
case RecentlyUsedDocuments: return i18n("Recently Used Documents");
|
||||
case Settings: return i18n("System Settings");
|
||||
case RunCommand: return i18n("Run Command...");
|
||||
case SwitchUser: return i18n("Switch User");
|
||||
case SaveSession: return i18n("Save Session");
|
||||
case LockScreen: return i18n("Lock Screen");
|
||||
|
@ -221,7 +220,6 @@ public:
|
|||
case RecentlyUsedApplications: return "document-open-recent";
|
||||
case RecentlyUsedDocuments: return "document-open-recent";
|
||||
case Settings: return "preferences-system";
|
||||
case RunCommand: return "system-run";
|
||||
case SwitchUser: return "system-switch-user";
|
||||
case SaveSession: return "document-save";
|
||||
case LockScreen: return "system-lock-screen";
|
||||
|
@ -299,7 +297,6 @@ MenuLauncherApplet::MenuLauncherApplet(QObject *parent, const QVariantList &args
|
|||
}
|
||||
default: { //Default configuration
|
||||
d->viewtypes << "RecentlyUsedApplications" << "Applications" << "Favorites";
|
||||
d->viewtypes << "RunCommand";
|
||||
d->viewtypes << "Leave";
|
||||
d->iconname = "start-here-kde";
|
||||
}
|
||||
|
@ -738,8 +735,6 @@ void MenuLauncherApplet::showMenu(bool pressed)
|
|||
m->addAction(KIcon(module.icon()), module.moduleName().replace('&',"&&"))->setData(KUrl("kcm:/" + entry->entryPath()));
|
||||
}
|
||||
}
|
||||
} else if(vtname == "RunCommand") {
|
||||
menuview->addAction(KIcon(d->viewIcon(RunCommand)), d->viewText(RunCommand))->setData(KUrl("leave:/run"));
|
||||
} else if(vtname == "SwitchUser") {
|
||||
menuview->addAction(KIcon(d->viewIcon(SwitchUser)), d->viewText(SwitchUser))->setData(KUrl("leave:/switch"));
|
||||
} else if(vtname == "SaveSession") {
|
||||
|
|
|
@ -49,7 +49,6 @@ public:
|
|||
Computer, ///< Computer Menu
|
||||
RecentlyUsed, ///< Recently Used Menu
|
||||
Settings, ///< Settings Menu
|
||||
RunCommand, ///< Run Command Action
|
||||
SwitchUser, ///< Switch User Action
|
||||
SaveSession, ///< Save Session Action (only enabled if restoreSavedSession is enabled)
|
||||
LockScreen, ///< Lock Screen Action
|
||||
|
|
|
@ -4,13 +4,9 @@ set(contextmenu_SRCS
|
|||
menu.cpp
|
||||
)
|
||||
|
||||
set(krunner_xml ${CMAKE_SOURCE_DIR}/krunner/dbus/org.kde.krunner.App.xml)
|
||||
QT4_ADD_DBUS_INTERFACE(contextmenu_SRCS ${krunner_xml} krunner_interface)
|
||||
|
||||
set(screensaver_xml ${CMAKE_SOURCE_DIR}/kscreensaver/org.freedesktop.ScreenSaver.xml)
|
||||
QT4_ADD_DBUS_INTERFACE(contextmenu_SRCS ${screensaver_xml} screensaver_interface)
|
||||
|
||||
|
||||
kde4_add_plugin(plasma_containmentactions_contextmenu ${contextmenu_SRCS})
|
||||
target_link_libraries(plasma_containmentactions_contextmenu KDE4::plasma KDE4::kio kworkspace)
|
||||
|
||||
|
|
|
@ -35,13 +35,11 @@
|
|||
#include <Plasma/Wallpaper>
|
||||
|
||||
#include "kworkspace/kworkspace.h"
|
||||
#include "krunner_interface.h"
|
||||
#include "screensaver_interface.h"
|
||||
|
||||
|
||||
ContextMenu::ContextMenu(QObject *parent, const QVariantList &args)
|
||||
: Plasma::ContainmentActions(parent, args),
|
||||
m_runCommandAction(0),
|
||||
m_lockScreenAction(0),
|
||||
m_logoutAction(0),
|
||||
m_separator1(0),
|
||||
|
@ -69,7 +67,7 @@ void ContextMenu::init(const KConfigGroup &config)
|
|||
m_actionOrder << "add widgets" << "_add panel" << "lock widgets" << "_context" << "remove";
|
||||
} else {
|
||||
actions.insert("configure shortcuts", false);
|
||||
m_actionOrder << "_context" << "_run_command" << "add widgets" << "_add panel"
|
||||
m_actionOrder << "_context" << "add widgets" << "_add panel"
|
||||
<< "manage activities" << "remove" << "lock widgets" << "_sep1"
|
||||
<<"_lock_screen" << "_logout" << "_sep2" << "configure"
|
||||
<< "configure shortcuts" << "_sep3" << "_wallpaper";
|
||||
|
@ -90,11 +88,7 @@ void ContextMenu::init(const KConfigGroup &config)
|
|||
if (c->containmentType() == Plasma::Containment::PanelContainment ||
|
||||
c->containmentType() == Plasma::Containment::CustomPanelContainment) {
|
||||
//FIXME: panel does its own config action atm...
|
||||
} else if (!m_runCommandAction) {
|
||||
m_runCommandAction = new QAction(i18n("Run Command..."), this);
|
||||
m_runCommandAction->setIcon(KIcon("system-run"));
|
||||
connect(m_runCommandAction, SIGNAL(triggered(bool)), this, SLOT(runCommand()));
|
||||
|
||||
} else if (!m_lockScreenAction) {
|
||||
m_lockScreenAction = new QAction(i18n("Lock Screen"), this);
|
||||
m_lockScreenAction->setIcon(KIcon("system-lock-screen"));
|
||||
connect(m_lockScreenAction, SIGNAL(triggered(bool)), this, SLOT(lockScreen()));
|
||||
|
@ -163,8 +157,6 @@ QAction *ContextMenu::action(const QString &name)
|
|||
if (c->corona() && c->corona()->immutability() == Plasma::Mutable) {
|
||||
return c->corona()->action("add panel");
|
||||
}
|
||||
} else if (name == "_run_command") {
|
||||
return m_runCommandAction;
|
||||
} else if (name == "_lock_screen") {
|
||||
return m_lockScreenAction;
|
||||
} else if (name == "_logout") {
|
||||
|
@ -176,13 +168,6 @@ QAction *ContextMenu::action(const QString &name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void ContextMenu::runCommand()
|
||||
{
|
||||
QString interface("org.kde.krunner");
|
||||
org::kde::krunner::App krunner(interface, "/App", QDBusConnection::sessionBus());
|
||||
krunner.display();
|
||||
}
|
||||
|
||||
void ContextMenu::lockScreen()
|
||||
{
|
||||
QString interface("org.freedesktop.ScreenSaver");
|
||||
|
|
|
@ -41,13 +41,11 @@ public:
|
|||
void save(KConfigGroup &config);
|
||||
|
||||
public slots:
|
||||
void runCommand();
|
||||
void lockScreen();
|
||||
void startLogout();
|
||||
void logout();
|
||||
|
||||
private:
|
||||
QAction *m_runCommandAction;
|
||||
QAction *m_lockScreenAction;
|
||||
QAction *m_logoutAction;
|
||||
QAction *m_separator1;
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
set(desktop_SRCS
|
||||
desktop.cpp
|
||||
itemspace.cpp
|
||||
desktoplayout.cpp)
|
||||
|
||||
set(krunner_xml ${CMAKE_SOURCE_DIR}/krunner/dbus/org.kde.krunner.App.xml)
|
||||
QT4_ADD_DBUS_INTERFACE(desktop_SRCS ${krunner_xml} krunner_interface)
|
||||
desktoplayout.cpp
|
||||
)
|
||||
|
||||
kde4_add_plugin(plasma_containment_desktop ${desktop_SRCS})
|
||||
target_link_libraries(plasma_containment_desktop KDE4::plasma KDE4::kio)
|
||||
|
|
|
@ -20,13 +20,9 @@
|
|||
|
||||
#include "desktop.h"
|
||||
|
||||
#include "krunner_interface.h"
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include <Plasma/Corona>
|
||||
|
||||
#include <QTimer>
|
||||
#include <Plasma/Corona>
|
||||
#include <KDebug>
|
||||
|
||||
using namespace Plasma;
|
||||
|
||||
|
@ -165,21 +161,6 @@ void DefaultDesktop::dropEvent(QGraphicsSceneDragDropEvent *event)
|
|||
dropping = false;
|
||||
}
|
||||
|
||||
void DefaultDesktop::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
// Only non-whitespace and printable characters may trigger KRunner,
|
||||
// otherwise a white-space character is introduced and the term you've
|
||||
// entered is not recognized
|
||||
if (focusItem() == this && !event->text().trimmed().isEmpty() && event->text()[0].isPrint()) {
|
||||
const QString interface("org.kde.krunner");
|
||||
org::kde::krunner::App krunner(interface, "/App", QDBusConnection::sessionBus());
|
||||
krunner.query(event->text());
|
||||
event->accept();
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
K_EXPORT_PLASMA_APPLET(desktop, DefaultDesktop)
|
||||
|
||||
#include "moc_desktop.cpp"
|
||||
|
|
|
@ -59,7 +59,6 @@ public:
|
|||
|
||||
protected:
|
||||
void dropEvent(QGraphicsSceneDragDropEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onAppletAdded(Plasma::Applet *, const QPointF &);
|
||||
|
|
|
@ -54,7 +54,7 @@ void KillRunnerConfig::load()
|
|||
{
|
||||
KCModule::load();
|
||||
|
||||
KSharedConfig::Ptr cfg = KSharedConfig::openConfig("krunnerrc");
|
||||
KSharedConfig::Ptr cfg = KSharedConfig::openConfig("plasma-desktoprc");
|
||||
KConfigGroup grp = cfg->group("Runners");
|
||||
grp = KConfigGroup(&grp, "Kill Runner");
|
||||
|
||||
|
@ -69,7 +69,7 @@ void KillRunnerConfig::save()
|
|||
{
|
||||
KCModule::save();
|
||||
|
||||
KSharedConfig::Ptr cfg = KSharedConfig::openConfig("krunnerrc");
|
||||
KSharedConfig::Ptr cfg = KSharedConfig::openConfig("plasma-desktoprc");
|
||||
KConfigGroup grp = cfg->group("Runners");
|
||||
grp = KConfigGroup(&grp, "Kill Runner");
|
||||
|
||||
|
|
|
@ -58,7 +58,6 @@ SessionRunner::SessionRunner(QObject *parent, const QVariantList &args)
|
|||
fastUserSwitchSyntax.addExampleQuery(i18n("new session"));
|
||||
addSyntax(fastUserSwitchSyntax);
|
||||
|
||||
//"SESSIONS" should not be translated; it's used programmaticaly
|
||||
setDefaultSyntax(Plasma::RunnerSyntax("SESSIONS", i18n("Lists all sessions")));
|
||||
|
||||
}
|
||||
|
@ -124,9 +123,7 @@ void SessionRunner::match(Plasma::RunnerContext &context)
|
|||
return;
|
||||
}
|
||||
|
||||
// first compare with SESSIONS. this must *NOT* be translated (i18n)
|
||||
// as it is used as an internal command trigger (e.g. via d-bus),
|
||||
// not as a user supplied query. and yes, "Ugh, magic strings"
|
||||
// first compare with SESSIONS
|
||||
bool listAll = (
|
||||
term.compare("SESSIONS", Qt::CaseInsensitive) == 0 ||
|
||||
term.compare(i18nc("User sessions", "sessions"), Qt::CaseInsensitive) == 0
|
||||
|
|
Loading…
Add table
Reference in a new issue