Commit 12530124 authored by Tomaz  Canabrava's avatar Tomaz Canabrava
Browse files

Revert "Revert "Movo Session to a independent static library""

This reverts commit f4bf8a42.
parent f4bf8a42
......@@ -37,13 +37,8 @@ option(KONSOLE_BUILD_UNI2CHARACTERWIDTH "Konsole: build uni2characterwidth execu
# qdbuscpp2xml -M -s ViewManager.h -o org.kde.konsole.Konsole.xml
# Generate dbus .xml files; do not store .xml in source folder
qt5_generate_dbus_interface(session/Session.h org.kde.konsole.Session.xml OPTIONS -m)
qt5_generate_dbus_interface(ViewManager.h org.kde.konsole.Window.xml OPTIONS -m)
qt5_add_dbus_adaptor(sessionadaptors_SRCS
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Session.xml
session/Session.h
Konsole::Session)
qt5_add_dbus_adaptor(windowadaptors_SRCS
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Window.xml
ViewManager.h
......@@ -106,9 +101,9 @@ target_link_libraries(konsolehelpers
add_subdirectory(colorscheme)
add_subdirectory(keyboardtranslator)
add_subdirectory(profile)
add_subdirectory(session)
set(konsoleprivate_SRCS ${sessionadaptors_SRCS}
${windowadaptors_SRCS}
set(konsoleprivate_SRCS ${windowadaptors_SRCS}
AutoScrollHandler.cpp
BookmarkHandler.cpp
BookmarkMenu.cpp
......@@ -166,13 +161,6 @@ set(konsoleprivate_SRCS ${sessionadaptors_SRCS}
history/compact/CompactHistoryLine.cpp
history/compact/CompactHistoryScroll.cpp
history/compact/CompactHistoryType.cpp
session/Session.cpp
session/SessionController.cpp
session/SessionDisplayConnection.cpp
session/SessionGroup.cpp
session/SessionListModel.cpp
session/SessionManager.cpp
session/SessionTask.cpp
widgets/DetachableTabBar.cpp
widgets/EditProfileDialog.cpp
widgets/HistorySizeWidget.cpp
......@@ -184,8 +172,8 @@ set(konsoleprivate_SRCS ${sessionadaptors_SRCS}
widgets/TerminalHeaderBar.cpp
widgets/ViewContainer.cpp
widgets/ViewSplitter.cpp
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Window.xml
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Session.xml)
widgets/KonsolePrintManager.cpp
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Window.xml)
kconfig_add_kcfg_files(konsoleprivate_SRCS settings/KonsoleSettings.kcfgc)
......@@ -195,7 +183,7 @@ ki18n_wrap_ui(konsoleprivate_SRCS
CopyInputDialog.ui
HistorySizeDialog.ui
KeyBindingEditor.ui
PrintOptions.ui
PrintOptions.ui # Temporary to build session static library
RenameTabDialog.ui
settings/GeneralSettings.ui
settings/PartInfo.ui
......@@ -227,6 +215,7 @@ target_link_libraries(konsoleprivate
keyboardtranslator
konsolehelpers
konsoleprofile
konsolesession
${konsole_LIBS}
)
......
# qdbuscpp2xml -m Session.h -o org.kde.konsole.Session.xml
# Generate dbus .xml files; do not store .xml in source folder
qt5_generate_dbus_interface(Session.h org.kde.konsole.Session.xml OPTIONS -m)
qt5_add_dbus_adaptor(
sessionadaptors_SRCS
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Session.xml
Session.h
Konsole::Session
)
set(konsole_session_SRCS
${sessionadaptors_SRCS}
Session.cpp
SessionController.cpp
SessionDisplayConnection.cpp
SessionGroup.cpp
SessionListModel.cpp
SessionManager.cpp
SessionTask.cpp
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Session.xml
)
add_library(konsolesession
STATIC
${konsole_session_SRCS}
)
target_link_libraries(
konsolesession
${konsole_LIBS}
konsoleprofile # TODO: Must be removed from here, Used only for ProfileCommandParser::parse in SessionManager::sessionProfileCommandReceived
)
......@@ -30,8 +30,6 @@
#include <QList>
#include <QMenu>
#include <QKeyEvent>
#include <QPrinter>
#include <QPrintDialog>
#include <QFileDialog>
#include <QPainter>
#include <QStandardPaths>
......@@ -63,7 +61,6 @@
#include "Emulation.h"
#include "Enumeration.h"
#include "HistorySizeDialog.h"
#include "PrintOptions.h"
#include "RenameTabDialog.h"
#include "SaveHistoryTask.h"
#include "ScreenWindow.h"
......@@ -142,6 +139,8 @@ SessionController::SessionController(Session* session, TerminalDisplay* view, QO
setupExtraActions();
}
connect(this, &SessionController::requestPrint, _sessionDisplayConnection->view(), &TerminalDisplay::printScreen);
actionCollection()->addAssociatedWidget(view);
const QList<QAction *> actionsList = actionCollection()->actions();
......@@ -667,7 +666,7 @@ void SessionController::setupCommonActions()
action->setShortcut(QKeySequence(Qt::META + Qt::Key_S));
#endif
action = KStandardAction::print(this, &SessionController::print_screen, collection);
action = KStandardAction::print(this, &SessionController::requestPrint, collection);
action->setText(i18n("&Print Screen..."));
collection->setDefaultShortcut(action, Konsole::ACCEL + Qt::SHIFT + Qt::Key_P);
......@@ -1568,37 +1567,6 @@ void SessionController::scrollBackOptionsChanged(int mode, int lines)
}
}
void SessionController::print_screen()
{
QPrinter printer;
QPointer<QPrintDialog> dialog = new QPrintDialog(&printer, _sessionDisplayConnection->view());
auto options = new PrintOptions();
dialog->setOptionTabs({options});
dialog->setWindowTitle(i18n("Print Shell"));
connect(dialog,
QOverload<>::of(&QPrintDialog::accepted),
options,
&Konsole::PrintOptions::saveSettings);
if (dialog->exec() != QDialog::Accepted) {
return;
}
QPainter painter;
painter.begin(&printer);
KConfigGroup configGroup(KSharedConfig::openConfig(), "PrintOptions");
if (configGroup.readEntry("ScaleOutput", true)) {
double scale = qMin(printer.pageRect().width() / static_cast<double>(_sessionDisplayConnection->view()->width()),
printer.pageRect().height() / static_cast<double>(_sessionDisplayConnection->view()->height()));
painter.scale(scale, scale);
}
_sessionDisplayConnection->view()->printContent(painter, configGroup.readEntry("PrinterFriendly", true));
}
void SessionController::saveHistory()
{
SessionTask* task = new SaveHistoryTask(this);
......
......@@ -178,6 +178,11 @@ Q_SIGNALS:
*/
void tabColoredByUser(bool set) const;
/**
* Emmited when the user request print screen.
*/
void requestPrint();
public Q_SLOTS:
/**
* Issues a command to the session to navigate to the specified URL.
......@@ -239,7 +244,6 @@ private Q_SLOTS:
void findNextInHistory();
void findPreviousInHistory();
void changeSearchMatch();
void print_screen();
void saveHistory();
void showHistoryOptions();
void clearHistory();
......
/*
Copyright 2020-2020 by Gustavo Carneiro <gcarneiroa@hotmail.com>
Copyright 2012-2020 by Kurt Hindenburg <kurt.hindenburg@gmail.com>
Copyright 2020-2020 by Tomaz Canabrava <tcanabrava@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.
*/
// Own
#include "KonsolePrintManager.h"
// Konsole
#include "PrintOptions.h"
// Qt
#include <QWidget>
#include <QPrinter>
#include <QPainter>
#include <QPointer>
#include <QPrintDialog>
// KDE
#include <KConfigGroup>
#include <KSharedConfig>
using namespace Konsole;
void KonsolePrintManager::printRequest(pPrintContent pContent, QWidget *parent)
{
QPrinter printer;
QPointer<QPrintDialog> dialog = new QPrintDialog(&printer, parent);
auto options = new PrintOptions();
dialog->setOptionTabs({options});
dialog->setWindowTitle(i18n("Print Shell"));
QObject::connect(dialog,
QOverload<>::of(&QPrintDialog::accepted),
options,
&Konsole::PrintOptions::saveSettings);
if (dialog->exec() != QDialog::Accepted) {
return;
}
QPainter painter;
painter.begin(&printer);
KConfigGroup configGroup(KSharedConfig::openConfig(), "PrintOptions");
if (configGroup.readEntry("ScaleOutput", true)) {
double scale = qMin(printer.pageRect().width() / static_cast<double>(parent->width()),
printer.pageRect().height() / static_cast<double>(parent->height()));
painter.scale(scale, scale);
}
pContent(painter, configGroup.readEntry("PrinterFriendly", true));
}
/*
Copyright 2020-2020 by Gustavo Carneiro <gcarneiroa@hotmail.com>
Copyright 2012-2020 by Kurt Hindenburg <kurt.hindenburg@gmail.com>
Copyright 2020-2020 by Tomaz Canabrava <tcanabrava@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 KONSOLEPRINTMANAGER_H
#define KONSOLEPRINTMANAGER_H
#include <functional>
class QWidget;
class QPainter;
namespace Konsole
{
class KonsolePrintManager
{
public:
typedef std::function<void (QPainter&, bool)> pPrintContent;
static void printRequest(pPrintContent pContent, QWidget *parent);
};
}
#endif
......@@ -80,6 +80,8 @@
#include "profile/Profile.h"
#include "ViewManager.h" // for colorSchemeForProfile. // TODO: Rewrite this.
#include "LineBlockCharacters.h"
#include "PrintOptions.h"
#include "KonsolePrintManager.h"
using namespace Konsole;
......@@ -1373,6 +1375,7 @@ void TerminalDisplay::paintEvent(QPaintEvent* pe)
void TerminalDisplay::printContent(QPainter& painter, bool friendly)
{
// TODO: Move this code to KonsolePrintManager
// Reinitialize the font with the printers paint device so the font
// measurement calculations will be done correctly
QFont savedFont = getVTFont();
......@@ -4128,3 +4131,11 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile)
setAlternateScrolling(profile->property<bool>(Profile::AlternateScrolling));
_dimValue = profile->dimValue();
}
void TerminalDisplay::printScreen()
{
auto lambda = [this](QPainter& painter, bool friendly) {
printContent(painter, friendly);
};
KonsolePrintManager::printRequest(lambda, this);
}
......@@ -341,7 +341,8 @@ public:
* Selects everything in the terminal
*/
void selectAll();
// TODO: Move this code to KonsolePrintManager
void printContent(QPainter &painter, bool friendly);
/**
......@@ -514,6 +515,10 @@ public Q_SLOTS:
// Used to show/hide the message widget
void updateReadOnlyState(bool readonly);
IncrementalSearchBar *searchBar() const;
// Used for requestPrint
void printScreen();
Q_SIGNALS:
void requestToggleExpansion();
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment