settings:expose LayoutTemplates to New button

pull/19/head
Michail Vourlakos 5 years ago
parent cd89f959e3
commit 77515be7c6

@ -134,8 +134,30 @@ void TabLayouts::initLayoutMenu()
m_newLayoutAction->setToolTip(i18n("New layout"));
m_newLayoutAction->setIcon(QIcon::fromTheme("add"));
m_newLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
/*Add Layout Templates for New Action*/
QMenu *layoutTemplatesSubMenu = new QMenu(m_layoutMenu);
connectActionWithButton(m_ui->newButton, m_newLayoutAction);
connect(m_newLayoutAction, &QAction::triggered, this, &TabLayouts::on_new_layout);
connect(m_newLayoutAction, &QAction::triggered, m_ui->newButton, &QPushButton::showMenu);
Data::LayoutsTable templates = m_corona->templatesManager()->systemLayoutTemplates();
for (int i=0; i<templates.rowCount(); ++i) {
if (i==2) {
layoutTemplatesSubMenu->addSeparator();
}
QAction *newlayout = layoutTemplatesSubMenu->addAction(templates[i].name);
QString templatename = templates[i].name;
connect(newlayout, &QAction::triggered, this, [&, templatename]() {
newLayout(templatename);
});
}
m_newLayoutAction->setMenu(layoutTemplatesSubMenu);
m_ui->newButton->setMenu(layoutTemplatesSubMenu);
layoutTemplatesSubMenu->setMinimumWidth(m_ui->newButton->width() * 2);
m_copyLayoutAction = m_layoutMenu->addAction(i18nc("copy layout", "&Copy"));
m_copyLayoutAction->setToolTip(i18n("Copy selected layout"));
@ -372,7 +394,7 @@ void TabLayouts::updatePerLayoutButtonsState()
setTwinProperty(m_detailsAction, TWINENABLED, true);
}
void TabLayouts::on_new_layout()
void TabLayouts::newLayout(const QString &templateName)
{
qDebug() << Q_FUNC_INFO;
@ -381,7 +403,7 @@ void TabLayouts::on_new_layout()
}
//! retrieve Default layout template
Data::Layout tdata = m_corona->templatesManager()->layoutTemplateForName(i18n(Latte::Templates::DEFAULTLAYOUTTEMPLATENAME));
Data::Layout tdata = m_corona->templatesManager()->layoutTemplateForName(templateName);
if (!tdata.isNull()) {
Data::Layout newlayout = m_layoutsController->addLayoutForFile(tdata.id, tdata.name, true);

@ -90,7 +90,6 @@ private slots:
void loadConfig();
void saveConfig();
void on_new_layout();
void on_copy_layout();
void on_download_layout();
void on_pause_layout();
@ -107,6 +106,8 @@ private slots:
void on_rawLayoutDropped(const QString &rawLayout);
void updatePerLayoutButtonsState();
void newLayout(const QString &templateName);
private:
bool isHoveringLayoutsTable(const QPoint &pos);

@ -76,6 +76,26 @@ Data::Layout Manager::layoutTemplateForName(const QString &layoutName)
return Data::Layout();
}
Data::LayoutsTable Manager::systemLayoutTemplates()
{
Data::LayoutsTable templates;
QString id = m_layoutTemplates.idForName(i18n(DEFAULTLAYOUTTEMPLATENAME));
templates << m_layoutTemplates[id];
id = m_layoutTemplates.idForName(i18n(EMPTYLAYOUTTEMPLATENAME));
templates << m_layoutTemplates[id];
for (int i=0; i<m_layoutTemplates.rowCount(); ++i) {
if ( m_layoutTemplates[i].name != i18n(DEFAULTLAYOUTTEMPLATENAME)
&& m_layoutTemplates[i].name != i18n(EMPTYLAYOUTTEMPLATENAME)
&& m_layoutTemplates[i].name != MULTIPLELAYOUTSTEMPLATENAME) {
templates << m_layoutTemplates[i];
}
}
return templates;
}
//! it is used just in order to provide translations for the presets
void Manager::exposeTranslatedTemplateNames()
{

@ -37,6 +37,7 @@ namespace Templates {
const char DEFAULTLAYOUTTEMPLATENAME[] = "Default";
const char EMPTYLAYOUTTEMPLATENAME[] = "Empty";
const char MULTIPLELAYOUTSTEMPLATENAME[] = "multiple-layouts_hidden";
class Manager : public QObject
{
@ -51,6 +52,8 @@ public:
Data::Layout layoutTemplateForName(const QString &layoutName);
Data::LayoutsTable systemLayoutTemplates();
private:
void exposeTranslatedTemplateNames();

Loading…
Cancel
Save