Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/print/internal/printprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@

#include "log.h"

using namespace mu;
using namespace mu::print;
using namespace muse;
using namespace muse::draw;
using namespace mu::notation;

namespace mu::print {
PrintProvider::PrintProvider(const kors::modularity::ContextPtr& iocCtx)
: Injectable(iocCtx)
{
}

Ret PrintProvider::printNotation(INotationPtr notation)
{
IF_ASSERT_FAILED(notation) {
Expand All @@ -49,14 +53,20 @@ Ret PrintProvider::printNotation(INotationPtr notation)
//printerDev.setCreator("MuseScore Studio Version: " VERSION);
printerDev.setFullPage(true);
if (!printerDev.setPageMargins(QMarginsF())) {
LOGD() << "unable to clear printer margins";
LOGW() << "unable to clear printer margins";
}

printerDev.setDocName(notation->projectWorkTitleAndPartName());
printerDev.setOutputFormat(QPrinter::NativeFormat);
printerDev.setFromTo(1, painting->pageCount());

QPrintDialog pd(&printerDev, 0);
QPrintDialog pd(&printerDev);
pd.setMinMax(1, painting->pageCount());

// HACK: ensure we have a valid windowHandle to which we can set a transient parent to
pd.winId();
// the print dialog needs a valid parent window to show the modern print dialog on Windows 11
pd.windowHandle()->setTransientParent(mainWindow()->qWindow());
if (!pd.exec()) {
return muse::make_ret(Ret::Code::Cancel);
}
Expand All @@ -77,3 +87,4 @@ Ret PrintProvider::printNotation(INotationPtr notation)

return muse::make_ok();
}
}
16 changes: 9 additions & 7 deletions src/print/internal/printprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MU_PRINT_PRINTPROVIDER_H
#define MU_PRINT_PRINTPROVIDER_H
#pragma once

#include "../iprintprovider.h"
#include "print/iprintprovider.h"

#include "global/modularity/ioc.h"
#include "ui/imainwindow.h"

namespace mu::print {
class PrintProvider : public IPrintProvider
class PrintProvider : public IPrintProvider, public muse::Injectable
{
muse::Inject<muse::ui::IMainWindow> mainWindow{ this };

public:
PrintProvider() = default;
explicit PrintProvider(const muse::modularity::ContextPtr&);

muse::Ret printNotation(notation::INotationPtr notation) override;
};
}

#endif // MU_PRINT_PRINTPROVIDER_H
4 changes: 3 additions & 1 deletion src/print/printmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
#include "printmodule.h"

#include <memory>

#include "modularity/ioc.h"

#include "internal/printprovider.h"
Expand All @@ -35,5 +37,5 @@ std::string PrintModule::moduleName() const

void PrintModule::registerExports()
{
ioc()->registerExport<IPrintProvider>(moduleName(), new PrintProvider());
ioc()->registerExport<IPrintProvider>(moduleName(), std::make_shared<PrintProvider>(iocContext()));
}
Loading