Exemplo n.º 1
0
AddBookmarkDialog::AddBookmarkDialog(QWidget *parent, CR3View * docView, CRBookmark * bm ) :
    QDialog(parent),
    m_ui(new Ui::AddBookmarkDialog),
    _docview( docView ),
    _bm(bm),
    _edit(bm!=NULL)
{
    initialized = false;
    m_ui->setupUi(this);
    setWindowTitle( tr("Add bookmark") );
    if ( _bm==NULL )
        _bm = docView->createBookmark();
    if ( _bm ) {
        if ( _bm->getType() == bmkt_pos ) {
            m_ui->cbType->addItem( tr("Position") );
        } else {
            m_ui->cbType->addItem( tr("Comment") );
            m_ui->cbType->addItem( tr("Correction") );
            m_ui->cbType->setCurrentIndex(0);
        }
        m_ui->edPositionText->setPlainText( cr2qt(_bm->getPosText()) );
        m_ui->edPositionText->setReadOnly( true );
        m_ui->edComment->setPlainText( cr2qt(_bm->getCommentText()) );
        m_ui->edComment->setReadOnly( false );
        m_ui->lblPosition->setText( crpercent(_bm->getPercent()) );
        m_ui->lblTitle->setText( cr2qt(_bm->getTitleText()) );
    }
    _docview->restoreWindowPos( this, "bookmarkedit." );
    initialized = true;
}
Exemplo n.º 2
0
void RecentBooksDlg::ShowPage(int updown, int selectRow)
{
    Device::forceFullScreenUpdate();

    if(updown>0) {
        if(curPage+1>pageCount) curPage=0;
        curPage+=1;
    } else {
        if(curPage-1<=0) curPage=pageCount+1;
        curPage-=1;
    }
    setWindowTitle(titleMask + " (" + QString::number(curPage) + "/" + QString::number(pageCount) + ")");

    int rc = m_docview->rowCount;
    int firstItem = m_docview->getDocView()->isDocumentOpened() ? 1 : 0;
    int startPos = ((curPage-1)*rc)+firstItem;
    LVPtrVector<CRFileHistRecord> & files = m_docview->getDocView()->getHistory()->getRecords();
    for(int k=startPos, index=0; index<rc*2; ++k, index+=2) {
        if(k<files.length()) {
            CRFileHistRecord * book = files.get(k);

            lString16 title = book->getTitle();
            lString16 author = book->getAuthor();
            lString16 series = book->getSeries();
            lString16 filename = book->getFileName();
            if(title.empty()) title = filename;
            QString fileExt = cr2qt(filename);
            fileExt = fileExt.mid(fileExt.lastIndexOf(".")+1);

            int fileSize = book->getFileSize();
            CRBookmark *bm = book->getLastPos();
            int percent = bm->getPercent();

            if(author.empty()) author = L"-";
            if(title.empty()) title = L"-";
            if(!series.empty()) series = L"(" + series + L")";

            QTableWidgetItem *item = m_ui->tableWidget->item(index, 0);
            item->setText(cr2qt(title));

            item = m_ui->tableWidget->item(index+1, 0);
            item->setText(cr2qt(author)+"\n"+cr2qt(series));

            item = m_ui->tableWidget->item(index+1, 1);
            item->setText(crpercent(percent) + "\n" + fileExt+" / "+crFileSize(fileSize));

            m_ui->tableWidget->showRow(index);
            m_ui->tableWidget->showRow(index+1);
        } else {
            m_ui->tableWidget->hideRow(index);
            m_ui->tableWidget->hideRow(index+1);
        }
    }
    // select first row
    if(m_ui->tableWidget->rowCount()>0)
        m_ui->tableWidget->selectRow(selectRow);
}
Exemplo n.º 3
0
BookmarkListDialog::BookmarkListDialog(QWidget *parent, CR3View * docView ) :
	QDialog(parent),
	m_ui(new Ui::BookmarkListDialog),
	_docview(docView)
{
	m_ui->setupUi(this);

	addAction(m_ui->actionRemoveBookmark);
	addAction(m_ui->actionRemoveAllBookmarks);
	QAction *actionSelect = m_ui->actionSelectBookmark;
	actionSelect->setShortcut(Qt::Key_Select);
	addAction(actionSelect);

	int i = 0;
	m_ui->tableWidget->horizontalHeader()->setResizeMode( i++, QHeaderView::ResizeToContents);
	m_ui->tableWidget->horizontalHeader()->setResizeMode( i++, QHeaderView::Stretch );
	m_ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
	m_ui->tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);

	CRFileHistRecord * rec = _docview->getDocView()->getCurrentFileHistRecord();
	if (!rec) return;
	LVPtrVector<CRBookmark> & list( rec->getBookmarks() );
	int curpercent = _docview->getDocView()->getPosPercent();
	int bestdiff = -1;
	int bestindex = -1;
	int y = 0;
	for ( int i=0; i<list.length(); i++ ) {
		CRBookmark * bm = list[i];
		if ( bm->getType() == bmkt_lastpos ) continue;
		int diff = bm->getPercent() - curpercent;
		if ( diff < 0 )
			diff = -diff;
		if ( bestindex==-1 || diff < bestdiff ) {
			bestindex = i;
			bestdiff = diff;
		}
		m_ui->tableWidget->setRowCount(y+1);
		{
			int i=0;
			_list.append( bm );
			m_ui->tableWidget->setItem( y, i++, new QTableWidgetItem(crpercent( bm->getPercent())));
			m_ui->tableWidget->setItem( y, i++, new QTableWidgetItem(limit(cr2qt(bm->getPosText()))));
			m_ui->tableWidget->verticalHeader()->setResizeMode(y, QHeaderView::ResizeToContents);
		}
		y++;
	}
	if (bestindex>=0) m_ui->tableWidget->selectRow(bestindex);

	m_ui->tableWidget->resizeColumnsToContents();
	m_ui->tableWidget->resizeRowsToContents();
}
Exemplo n.º 4
0
RecentBooksDlg::RecentBooksDlg(QWidget *parent, CR3View * docView )
    : Dialog(parent)
    , ui(new Ui::RecentBooksDlg)
    , docview(docView)
{
    ui->setupUi(this);

    QFont f(ui->tableWidget->font());
    f.setPointSize(docview->getOptions()->getIntDef("cr3.app.ui.recent.font.size", 12));
    ui->tableWidget->setFont(f);

    f = ui->lblPosition->font();
    f.setPointSize(f.pointSize()/2);
    ui->lblPosition->setFont(f);

    f = ui->lblTitle->font();
    f.setBold(true);
    ui->lblTitle->setFont(f);

    ui->tableWidget->setColumnCount(1);

    ui->tableWidget->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
    ui->tableWidget->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
    ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Custom);

    bool isVscroll = docview->getOptions()->getIntDef(PROP_APP_UI_RECENT_VSCROLLBAR, 1) != 0;
    ui->tableWidget->setVerticalScrollBarPolicy(isVscroll? Qt::ScrollBarAsNeeded : Qt::ScrollBarAlwaysOff);
    bool isHscroll = docview->getOptions()->getIntDef(PROP_APP_UI_RECENT_HSCROLLBAR, 1) != 0;
    ui->tableWidget->setHorizontalScrollBarPolicy(isHscroll? Qt::ScrollBarAsNeeded : Qt::ScrollBarAlwaysOff);

    // fill rows
    QFont fontTitle = ui->tableWidget->font();
    fontTitle.setBold(true);

    QFont fontAuthor = ui->tableWidget->font();
    fontAuthor.setItalic(true);

    QFont fontInfo = ui->tableWidget->font();
    fontInfo.setItalic(true);
    fontInfo.setPointSize(fontInfo.pointSize()*2/3);

    QFontMetrics tfm(fontTitle);
    QFontMetrics afm(fontAuthor);

    int rowHeight = tfm.height() + afm.height();
    ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Fixed);
    ui->tableWidget->verticalHeader()->setDefaultSectionSize(rowHeight);

    ui->tableWidget->setItemDelegate(new RecentBooksListDelegate(ui->tableWidget, fontTitle, fontAuthor));

    LVPtrVector<CRFileHistRecord>& files = docview->getDocView()->getHistory()->getRecords();

    // remove non-existing entries
    for( int k=0; k<files.length(); )
    {
        QString fn(cr2qt(files.get(k)->getFilePathName()));
        if (!QFile::exists(fn))
            files.remove(k);
        else
            ++k;
    }

    ui->tableWidget->setRowCount( files.length() );

    // insert items
    for( int index=0; index<files.length(); ++index )
    {
        CRFileHistRecord* book = files.get(index);

        RecentTableWidgetItem* titleItem = new RecentTableWidgetItem();
        titleItem->title   = cr2qt(book->getTitle());
        if ( titleItem->title.isEmpty() )
            titleItem->title = cr2qt(book->getFileName());
        titleItem->info  = cr2qt(book->getAuthor());
        if ( titleItem->info.isEmpty() )
            titleItem->info = "-";
        titleItem->percent = " " + crpercent(book->getLastPos()->getPercent());

        ui->tableWidget->setItem(index, 0, titleItem);
    }

    ui->navBar->setControls(ui->tableWidget, ui->lblPosition,
                            QSize( docview->getOptions()->getIntDef(PROP_APP_UI_SWIPES_X_WEIGHT, 1),
                                   docview->getOptions()->getIntDef(PROP_APP_UI_SWIPES_Y_WEIGHT, 1) ) );

    ui->tableWidget->setEditFocus(true);
    ui->tableWidget->setCurrentCell(0,0);

    QObject::connect( ui->tableWidget, SIGNAL(itemActivated(QTableWidgetItem*)), this, SLOT(onClicked(QTableWidgetItem*)) );
    QObject::connect( ui->tableWidget, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(onClicked(QTableWidgetItem*)) );

    init();
}