Skip to content

Commit

Permalink
Dynamic window title and icon for tab dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed May 3, 2012
1 parent 5b618aa commit 061e7ea
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 46 deletions.
1 change: 0 additions & 1 deletion src/copyq.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<file>images/tab_commands.svg</file>
<file>images/tab_history.svg</file>
<file>images/tab_shortcuts.svg</file>
<file>images/new_tab.svg</file>
<file>images/command_move.svg</file>
<file>images/command_tab.svg</file>
<file>images/copy.svg</file>
Expand Down
33 changes: 0 additions & 33 deletions src/images/new_tab.svg

This file was deleted.

18 changes: 17 additions & 1 deletion src/include/tabdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ namespace Ui {
class TabDialog;
}

/**
* Dialog for naming and renaming tabs.
*/
class TabDialog : public QDialog
{
Q_OBJECT

public:
explicit TabDialog(QWidget *parent = 0);
/** Tab dialog type (new tab or rename existing tab). */
typedef enum {
TabNew,
TabRename
} TabDialogType;

explicit TabDialog(TabDialogType type, QWidget *parent = 0);
~TabDialog();

/** Set existing tabs for validation. */
Expand All @@ -46,10 +55,17 @@ class TabDialog : public QDialog
QStringList m_tabs;

signals:
/** Signal emitted if tab name is accepted. */
void accepted(const QString &name);

private slots:
void onAccepted();

/**
* Validate tab name.
* Tab name should be non-empty and should not be in existing tab list
* (see setTabs()).
*/
void validate();
};

Expand Down
5 changes: 2 additions & 3 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ void MainWindow::action(const QString &text, const Command &cmd)

void MainWindow::newTab()
{
TabDialog *d = new TabDialog(this);
TabDialog *d = new TabDialog(TabDialog::TabNew, this);
d->setTabs(tabs());

connect( d, SIGNAL(accepted(QString)),
Expand All @@ -887,8 +887,7 @@ void MainWindow::newTab()

void MainWindow::renameTab()
{
TabDialog *d = new TabDialog(this);
d->setWindowTitle(tr("CopyQ Rename Tab"));
TabDialog *d = new TabDialog(TabDialog::TabRename, this);
d->setTabs(tabs());
d->setTabName(browser()->getID());

Expand Down
10 changes: 9 additions & 1 deletion src/tabdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@

#include <QPushButton>

TabDialog::TabDialog(QWidget *parent)
TabDialog::TabDialog(TabDialog::TabDialogType type, QWidget *parent)
: QDialog(parent)
, ui(new Ui::TabDialog)
{
ui->setupUi(this);

if (type == TabNew) {
setWindowTitle( tr("CopyQ New Tab") );
setWindowIcon( QIcon(":/images/tab_new.svg") );
} else {
setWindowTitle( tr("CopyQ Rename Tab") );
setWindowIcon( QIcon(":/images/tab_rename.svg") );
}

connect( this, SIGNAL(accepted()),
this, SLOT(onAccepted()) );

Expand Down
7 changes: 0 additions & 7 deletions src/ui/tabdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>CopyQ New Tab</string>
</property>
<property name="windowIcon">
<iconset resource="copyq.qrc">
<normaloff>:/images/new_tab.svg</normaloff>:/images/new_tab.svg</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down

0 comments on commit 061e7ea

Please sign in to comment.