mirror of
https://github.com/loimu/zeit.git
synced 2025-09-15 12:58:44 +08:00
zeit: shorten text instead of wrapping it
This commit is contained in:
parent
49f442d141
commit
637615db5f
@ -31,3 +31,10 @@ void BaseDelegate::setIcon(QListWidgetItem* item, bool enabled) {
|
||||
QString icon = enabled ? QSL("dialog-ok-apply") : QSL("edit-delete");
|
||||
item->setIcon(QIcon::fromTheme(icon, QIcon(QSL(":/icons/") + icon)));
|
||||
}
|
||||
|
||||
QString BaseDelegate::elideText(const QString& text) const {
|
||||
const QFontMetrics& fm = ui->listWidget->fontMetrics();
|
||||
return fm.elidedText(text,
|
||||
isElidedTextEnabled ? Qt::ElideRight : Qt::ElideNone,
|
||||
ui->listWidget->width() - 36 /* hardcoded icon size */);
|
||||
}
|
||||
|
||||
@ -45,6 +45,8 @@ public:
|
||||
BaseDelegate(Ui::MainWindow* ui = nullptr);
|
||||
virtual ~BaseDelegate() {}
|
||||
|
||||
void enableElidedText(bool enabled) { isElidedTextEnabled = enabled; }
|
||||
|
||||
virtual void view()=0;
|
||||
virtual void copyEntry(int index)=0;
|
||||
virtual void createEntry()=0;
|
||||
@ -53,9 +55,11 @@ public:
|
||||
virtual void toggleEntry(int index)=0;
|
||||
|
||||
protected:
|
||||
bool isElidedTextEnabled = false;
|
||||
Ui::MainWindow* ui;
|
||||
|
||||
void setIcon(QListWidgetItem* item, bool enabled);
|
||||
QString elideText(const QString& text) const;
|
||||
};
|
||||
|
||||
#endif // BASEDELEGATE_H
|
||||
|
||||
@ -34,20 +34,19 @@ TaskDelegate::TaskDelegate(Ui::MainWindow* ui, CTCron* cron_)
|
||||
toolTip = tr("crontab tasks, running periodically");
|
||||
}
|
||||
|
||||
void TaskDelegate::view()
|
||||
{
|
||||
void TaskDelegate::view() {
|
||||
ui->listWidget->setEnabled(cron->isCurrentUserCron() || ROOT_ACTIONS);
|
||||
ui->labelWarning->setVisible(ROOT_ACTIONS);
|
||||
ui->listWidget->clear();
|
||||
for(CTTask* task: cron->tasks()) {
|
||||
QListWidgetItem* item = new QListWidgetItem();
|
||||
QString text(tr("Description: %1\n"
|
||||
"Runs %2\n"
|
||||
"Command: %3",
|
||||
"Runs at 'period described'")
|
||||
.arg(task->comment, task->describe(), task->command));
|
||||
item->setText(text);
|
||||
setIcon(item, task->enabled);
|
||||
QString text(QStringLiteral("%1\n%2\n%3").arg(
|
||||
elideText(tr("Description: ") + task->comment),
|
||||
elideText(tr("Runs ", "Runs at 'period described'")
|
||||
+ task->describe()),
|
||||
elideText(tr("Command: ") + task->command)));
|
||||
item->setText(text);
|
||||
ui->listWidget->addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,8 +130,10 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent),
|
||||
connect(group, &QActionGroup::triggered, this, &MainWindow::switchView);
|
||||
connect(ui->actionShowFilter, &QAction::toggled,
|
||||
this, &MainWindow::toggleFilter);
|
||||
connect(ui->actionWrapText, &QAction::toggled,
|
||||
ui->listWidget, &QListWidget::setWordWrap);
|
||||
connect(ui->actionShortenText, &QAction::toggled, this, [this] (bool enabled) {
|
||||
list->enableElidedText(enabled);
|
||||
list->view();
|
||||
});
|
||||
// Tools menu
|
||||
connect(ui->actionAlarm, &QAction::triggered,
|
||||
this, &MainWindow::showAlarmDialog);
|
||||
@ -140,8 +142,6 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent),
|
||||
// Help menu
|
||||
connect(ui->actionAbout, &QAction::triggered,
|
||||
this, &MainWindow::showAboutDialog);
|
||||
updateWindow();
|
||||
refreshActions(false);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
@ -151,11 +151,22 @@ MainWindow::~MainWindow() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::show() {
|
||||
QMainWindow::show();
|
||||
updateWindow();
|
||||
refreshActions(false);
|
||||
}
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent* e) {
|
||||
if(e->key() == Qt::Key_Escape && ui->filterEdit->isVisible())
|
||||
ui->actionShowFilter->trigger();
|
||||
}
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent* e) {
|
||||
QMainWindow::resizeEvent(e);
|
||||
list->view();
|
||||
}
|
||||
|
||||
void MainWindow::refreshActions(bool enabled) {
|
||||
bool currentUser = cron->isCurrentUserCron() || ROOT_ACTIONS;
|
||||
ui->toggleItemAction->setDisabled(ui->actionCommands->isChecked() || !enabled);
|
||||
@ -188,6 +199,7 @@ void MainWindow::switchView() {
|
||||
list = new CommandDelegate(ui, commands);
|
||||
else
|
||||
list = new TaskDelegate(ui, cron);
|
||||
list->enableElidedText(ui->actionShortenText->isChecked());
|
||||
updateWindow();
|
||||
}
|
||||
|
||||
|
||||
@ -44,6 +44,7 @@ class MainWindow : public QMainWindow
|
||||
Commands* commands;
|
||||
BaseDelegate* list = nullptr;
|
||||
void keyPressEvent(QKeyEvent*);
|
||||
void resizeEvent(QResizeEvent*);
|
||||
void refreshActions(bool);
|
||||
void updateWindow();
|
||||
void switchView();
|
||||
@ -56,6 +57,7 @@ class MainWindow : public QMainWindow
|
||||
public:
|
||||
explicit MainWindow(QWidget* parent = nullptr);
|
||||
~MainWindow();
|
||||
void show();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
@ -115,7 +115,7 @@
|
||||
<addaction name="actionCommands"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionShowFilter"/>
|
||||
<addaction name="actionWrapText"/>
|
||||
<addaction name="actionShortenText"/>
|
||||
</widget>
|
||||
<addaction name="menuAdd"/>
|
||||
<addaction name="menuView"/>
|
||||
@ -263,7 +263,7 @@
|
||||
<string notr="true">Ctrl+F</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionWrapText">
|
||||
<action name="actionShortenText">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -271,10 +271,10 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Wrap Text</string>
|
||||
<string>S&horten Text</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string notr="true">Ctrl+W</string>
|
||||
<string notr="true">Ctrl+H</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="toggleItemAction">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user