Skip to content

Commit

Permalink
Changing tabs and (de)selecting items
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed May 12, 2012
1 parent b25af98 commit 054d297
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Doxyfile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -323,12 +323,12 @@ EXTRACT_ALL = NO
# If the EXTRACT_PRIVATE tag is set to YES all private members of a class # If the EXTRACT_PRIVATE tag is set to YES all private members of a class
# will be included in the documentation. # will be included in the documentation.


EXTRACT_PRIVATE = NO EXTRACT_PRIVATE = YES


# If the EXTRACT_STATIC tag is set to YES all static members of a file # If the EXTRACT_STATIC tag is set to YES all static members of a file
# will be included in the documentation. # will be included in the documentation.


EXTRACT_STATIC = NO EXTRACT_STATIC = YES


# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) # If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
# defined locally in source files will be included in the documentation. # defined locally in source files will be included in the documentation.
Expand Down
10 changes: 8 additions & 2 deletions src/include/mainwindow.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class MainWindow : public QMainWindow
QSystemTrayIcon *tray; QSystemTrayIcon *tray;
bool m_browsemode; bool m_browsemode;
bool m_confirmExit; bool m_confirmExit;
int m_trayitems; int m_trayItems;
int m_lastTab;
QTimer *m_timerSearch; QTimer *m_timerSearch;


QMap<Action*,QAction*> m_actions; QMap<Action*,QAction*> m_actions;
Expand Down Expand Up @@ -207,12 +208,17 @@ class MainWindow : public QMainWindow
//!< Tab name of target tab (first tab if empty). //!< Tab name of target tab (first tab if empty).
); );


/** Set next or first tab as current. */
void nextTab();
/** Set previous or last tab as current. */
void previousTab();

private slots: private slots:
void updateTrayMenuItems(); void updateTrayMenuItems();
void trayActivated(QSystemTrayIcon::ActivationReason reason); void trayActivated(QSystemTrayIcon::ActivationReason reason);
void trayMenuAction(QAction *act); void trayMenuAction(QAction *act);
void enterSearchMode(const QString &txt); void enterSearchMode(const QString &txt);
void tabChanged(); void tabChanged(int current);
void tabMoved(int from, int to); void tabMoved(int from, int to);
void tabMenuRequested(const QPoint &pos, int tab); void tabMenuRequested(const QPoint &pos, int tab);
void tabCloseRequested(int tab); void tabCloseRequested(int tab);
Expand Down
57 changes: 46 additions & 11 deletions src/mainwindow.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ MainWindow::MainWindow(QWidget *parent)
, tray(NULL) , tray(NULL)
, m_browsemode(false) , m_browsemode(false)
, m_confirmExit(true) , m_confirmExit(true)
, m_trayitems(5) , m_trayItems(5)
, m_lastTab(-1)
, m_timerSearch( new QTimer(this) ) , m_timerSearch( new QTimer(this) )
, m_actions() , m_actions()
{ {
Expand Down Expand Up @@ -77,7 +78,7 @@ MainWindow::MainWindow(QWidget *parent)
connect( tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), connect( tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)) ); this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)) );
connect( ui->tabWidget, SIGNAL(currentChanged(int)), connect( ui->tabWidget, SIGNAL(currentChanged(int)),
this, SLOT(tabChanged()) ); this, SLOT(tabChanged(int)) );
connect( ui->tabWidget, SIGNAL(tabMoved(int, int)), connect( ui->tabWidget, SIGNAL(tabMoved(int, int)),
this, SLOT(tabMoved(int, int)) ); this, SLOT(tabMoved(int, int)) );
connect( ui->tabWidget, SIGNAL(tabMenuRequested(QPoint, int)), connect( ui->tabWidget, SIGNAL(tabMenuRequested(QPoint, int)),
Expand Down Expand Up @@ -111,7 +112,7 @@ MainWindow::MainWindow(QWidget *parent)


void MainWindow::exit() void MainWindow::exit()
{ {
int answer; int answer = QMessageBox::Yes;
if ( m_confirmExit ) { if ( m_confirmExit ) {
answer = QMessageBox::question( answer = QMessageBox::question(
this, this,
Expand All @@ -121,7 +122,7 @@ void MainWindow::exit()
QMessageBox::Yes); QMessageBox::Yes);
} }


if ( !m_confirmExit || answer == QMessageBox::Yes) { if (answer == QMessageBox::Yes) {
close(); close();
QApplication::exit(); QApplication::exit();
} }
Expand Down Expand Up @@ -376,10 +377,10 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
enterBrowseMode(false); enterBrowseMode(false);
break; break;
case Qt::Key_Tab: case Qt::Key_Tab:
w->setCurrentIndex( (w->currentIndex() + 1) % w->count() ); nextTab();
break; break;
case Qt::Key_Backtab: case Qt::Key_Backtab:
w->setCurrentIndex( (w->currentIndex() - 1) % w->count() ); previousTab();
break; break;
default: default:
QMainWindow::keyPressEvent(event); QMainWindow::keyPressEvent(event);
Expand All @@ -401,11 +402,11 @@ void MainWindow::keyPressEvent(QKeyEvent *event)


case Qt::Key_Left: case Qt::Key_Left:
if ( browser()->hasFocus() ) if ( browser()->hasFocus() )
ui->tabWidget->previousTab(); previousTab();
break; break;
case Qt::Key_Right: case Qt::Key_Right:
if ( browser()->hasFocus() ) if ( browser()->hasFocus() )
ui->tabWidget->nextTab(); nextTab();
break; break;


case Qt::Key_Return: case Qt::Key_Return:
Expand Down Expand Up @@ -468,7 +469,7 @@ void MainWindow::loadSettings()


ConfigurationManager *cm = ConfigurationManager::instance(); ConfigurationManager *cm = ConfigurationManager::instance();
m_confirmExit = cm->value("confirm_exit").toBool(); m_confirmExit = cm->value("confirm_exit").toBool();
m_trayitems = cm->value("tray_items").toInt(); m_trayItems = cm->value("tray_items").toInt();


/* are tabs already loaded? */ /* are tabs already loaded? */
bool loaded = ui->tabWidget->count() > 0; bool loaded = ui->tabWidget->count() > 0;
Expand Down Expand Up @@ -570,7 +571,7 @@ WId MainWindow::showMenu()
return wid; return wid;
} }


void MainWindow::tabChanged() void MainWindow::tabChanged(int current)
{ {
// update item menu (necessary for keyboard shortcuts to work) // update item menu (necessary for keyboard shortcuts to work)
QMenu *m = itemMenu; QMenu *m = itemMenu;
Expand All @@ -579,6 +580,30 @@ void MainWindow::tabChanged()
menuBar()->insertMenu( m->menuAction(), itemMenu ); menuBar()->insertMenu( m->menuAction(), itemMenu );
menuBar()->removeAction( m->menuAction() ); menuBar()->removeAction( m->menuAction() );
browser()->filterItems( ui->searchBar->text() ); browser()->filterItems( ui->searchBar->text() );

ClipboardBrowser *c;
TabWidget *tabs = ui->tabWidget;

if ( m_lastTab >= 0 && m_lastTab < tabs->count() ) {
c = browser(m_lastTab);
QModelIndex current = c->currentIndex();
if ( current.isValid() ) {
QModelIndexList indexes = c->selectionModel()->selectedIndexes();
if ( current.row() == 0 && (indexes.isEmpty() ||
(indexes.size() == 1 && indexes.first() == current)) ) {
c->setCurrentIndex( QModelIndex() );
}
}
}

if ( current >= 0 ) {
c = browser();
if( !c->currentIndex().isValid() ) {
c->setCurrent(0);
}
}

m_lastTab = current;
} }


void MainWindow::tabMoved(int, int) void MainWindow::tabMoved(int, int)
Expand Down Expand Up @@ -660,6 +685,16 @@ void MainWindow::addToTab(QMimeData *data, const QString &tabName)
c->setAutoUpdate(true); c->setAutoUpdate(true);
} }


void MainWindow::nextTab()
{
ui->tabWidget->nextTab();
}

void MainWindow::previousTab()
{
ui->tabWidget->previousTab();
}

void MainWindow::addItems(const QStringList &items, const QString &tabName) void MainWindow::addItems(const QStringList &items, const QString &tabName)
{ {
ClipboardBrowser *c = tabName.isEmpty() ? browser(0) : ClipboardBrowser *c = tabName.isEmpty() ? browser(0) :
Expand Down Expand Up @@ -768,7 +803,7 @@ void MainWindow::updateTrayMenuItems()
menu->removeAction(actions[i]); menu->removeAction(actions[i]);
sep = actions[i]; sep = actions[i];


len = qMin( m_trayitems, c->length() ); len = qMin( m_trayItems, c->length() );
unsigned char hint('0'); unsigned char hint('0');
for( i = 0; i < len; ++i ) { for( i = 0; i < len; ++i ) {
QString text = c->itemText(i); QString text = c->itemText(i);
Expand Down

0 comments on commit 054d297

Please sign in to comment.