⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookcase.cpp

📁 bookcase,by shell script and c++ and perl
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  }  m_configDlg->show();}void Bookcase::slotHideConfigDialog() {  if(m_configDlg) {    m_configDlg->delayedDestruct();    m_configDlg = 0;  }}void Bookcase::slotStatusMsg(const QString& text_) {  statusBar()->clear();  // add a space at the beginning and end for asthetic reasons  statusBar()->changeItem(QString::fromLatin1(" ")+text_+QString::fromLatin1(" "), ID_STATUS_MSG);  kapp->processEvents();}void Bookcase::slotUnitCount() {  // I add a space before and after for asthetic reasons  QString text = QString::fromLatin1(" ");  BCCollectionListIterator it(m_doc->collectionList());  for( ; it.current(); ++it) {    text += i18n("%1 Total").arg(it.current()->unitTitle());    text += QString::fromLatin1(": ");    text += QString::number(it.current()->unitCount());  }  text += QString::fromLatin1(" ");  statusBar()->changeItem(text, ID_STATUS_COUNT);}void Bookcase::slotDeleteUnit(BCUnit* unit_) {  m_doc->slotDeleteUnit(unit_);  m_editWidget->slotSetContents(0);  m_detailedView->slotSetSelected(0);  m_groupView->slotSetSelected(0);}//void Bookcase::slotFileNewCollection() {//  kdDebug() << "Bookcase::slotFileNewCollection()" << endl;//}void Bookcase::slotEnableOpenedActions(bool opened_ /*= true*/) {  // collapse all the groups (depth=1)  m_groupView->slotCollapseAll(1);  // expand the collections  m_groupView->slotExpandAll(0);  m_fileSaveAs->setEnabled(opened_);  m_filePrint->setEnabled(opened_);  m_exportBibtex->setEnabled(opened_);  m_exportBibtexml->setEnabled(opened_);  m_exportXSLT->setEnabled(opened_);  m_editFind->setEnabled(opened_);}void Bookcase::slotEnableModifiedActions(bool modified_ /*= true*/) {  setCaption(m_doc->URL().fileName(), modified_);  m_fileSave->setEnabled(modified_);}void Bookcase::slotUpdateFractionDone(float f_) {  // first check bounds  f_ = (f_ < 0.0) ? 0.0 : f_;  f_ = (f_ > 1.0) ? 1.0 : f_;  if(!m_progress->isVisible()) {    m_progress->show();  }  m_progress->setValue(static_cast<int>(f_ * 100.0));  kapp->processEvents();  if(f_ == 1.0) {    m_progress->hide();  }}void Bookcase::slotHandleConfigChange() {  // for some reason, the m_config pointer is getting changed, but  // I can't figure out where, so just to be on the safe side  if(m_config != kapp->config()) {    m_config = kapp->config();  }  bool showCount = m_configDlg->configValue(QString::fromLatin1("showCount"));  m_groupView->showCount(showCount, m_doc->collectionList());    m_configDlg->saveConfiguration(m_config);}void Bookcase::updateCollectionToolBar() {//  kdDebug() << "Bookcase::updateCollectionToolBar()" << endl;  //TODO fix this later  BCCollection* coll = m_doc->collectionById(0);  if(!coll) {    return;  }    QString current = m_groupView->collGroupBy(coll->unitName());  if(current.isEmpty()) {    current = coll->defaultGroupAttribute();    m_groupView->setGroupAttribute(coll, current);  }  QStringList groupTitles;  int index = 0;  QStringList groups = coll->unitGroups();  QStringList::Iterator it = groups.begin();  for(int i = 0; it != groups.end(); ++it, ++i) {    QString groupName = static_cast<QString>(*it);    BCAttribute* att = coll->attributeByName(groupName);    groupTitles << att->title();    if(groupName == current) {      index = i;    }  }// is it more of a performance hit to compare two stringlists then to repopulate needlessly?//  if(groupTitles != m_unitGrouping->items()) {    m_unitGrouping->setItems(groupTitles);//  }  m_unitGrouping->setCurrentItem(index);//  kdDebug() << "Bookcase::updateCollectionToolBar - setting index " << index << " for " << groupTitles[index] << endl;}void Bookcase::slotChangeGrouping() {//  kdDebug() << "Bookcase::slotChangeGrouping()" << endl;  unsigned idx = m_unitGrouping->currentItem();  BCCollectionListIterator collIt(m_doc->collectionList());  for( ; collIt.current(); ++collIt) {    BCCollection* coll = collIt.current();    QString groupName;    if(idx < coll->unitGroups().count()) {      groupName = coll->unitGroups()[idx];    } else {      groupName = coll->defaultGroupAttribute();    }//    kdDebug() << "\tchange to " << groupName << endl;    m_groupView->setGroupAttribute(coll, groupName);  }}void Bookcase::slotUpdateCollection(BCCollection* coll_) {//  kdDebug() << "Bookcase::slotUpdateCollection()" << endl;    updateCollectionToolBar();  slotUnitCount();  connect(coll_, SIGNAL(signalGroupModified(BCCollection*, BCUnitGroup*)),          m_groupView, SLOT(slotModifyGroup(BCCollection*, BCUnitGroup*)));}void Bookcase::doPrint(const QString& html_) {  KHTMLPart* w = new KHTMLPart();  w->begin(m_doc->URL());  w->write(html_);  w->end();  // the problem with doing my own layout is that the text gets truncated, both at the// top and at the bottom. Even adding the overlap parameter, there were problems.// KHTMLView takes care of that with a truncatedAt() parameter, but that's hidden in// the khtml::render_root class. So for now, just use the KHTMLView::print() method.// in KDE 3.1, there's an added option for printing a header with the date, url, and// page number#if 1  w->view()->print();#else  KPrinter* printer = new KPrinter(QPrinter::PrinterResolution);  if(printer->setup(this)) {    //viewport()->setCursor(waitCursor);    printer->setFullPage(false);    printer->setCreator("Bookcase");    printer->setDocName(m_doc->URL().url());    QPainter *p = new QPainter;    p->begin(printer);        // mostly taken from KHTMLView::print()    QString headerLeft = KGlobal::locale()->formatDate(QDate::currentDate(), false);    QString headerRight = m_doc->URL().url();    QString footerMid;        QFont headerFont("helvetica", 8);    p->setFont(headerFont);    const int lspace = p->fontMetrics().lineSpacing();    const int headerHeight = (lspace * 3) / 2;        QPaintDeviceMetrics metrics(printer);    const int pageHeight = metrics.height() - 2*headerHeight;    const int pageWidth = metrics.width();            //    kdDebug() << "Bookcase::doPrint() - pageHeight = " << pageHeight << ""//                 "; contentsHeight = " << w->view()->contentsHeight() << endl;    int top = 0;    int page = 1;    bool more = true;    while(more) {      p->setPen(Qt::black);      p->setFont(headerFont);      footerMid = i18n("Page %1").arg(page);      p->drawText(0, 0, pageWidth, lspace, Qt::AlignLeft, headerLeft);      p->drawText(0, 0, pageWidth, lspace, Qt::AlignRight, headerRight);      p->drawText(0, pageHeight+headerHeight, pageWidth, lspace, Qt::AlignHCenter, footerMid);      w->paint(p, QRect(0, -top + 2*headerHeight, pageWidth, pageHeight+top), top, &more);      top += pageHeight - PRINTED_PAGE_OVERLAP;      if(more) {        printer->newPage();        page++;      }//      p->resetXForm();    }    // stop painting, this will automatically send the print data to the printer    p->end();    delete p;  }  delete printer;#endif  delete w;}void Bookcase::XSLTError() {  QString str = i18n("Bookcase encountered an error in XSLT processing.\n");  str += i18n("Please check your installation.");  KMessageBox::sorry(this, str);}void Bookcase::FileError(const QString& filename) {  QString str = i18n("Bookcase is unable to find a required file - %1.\n").arg(filename);  str += i18n("Please check your installation.");  KMessageBox::sorry(this, str);}void Bookcase::slotExportBibtex() {  slotStatusMsg(i18n("Exporting..."));  if(m_doc->isEmpty()) {    slotStatusMsg(i18n("Ready."));    return;  }  QString filename(QString::fromLatin1("bookcase2bibtex.xsl"));    QString filter = i18n("*.bib|Bibtex files (*.bib)");  filter += QString::fromLatin1("\n");  filter += i18n("*|All files");  exportUsingXSLT(filename, filter);  slotStatusMsg(i18n("Ready."));}void Bookcase::slotExportBibtexml() {  slotStatusMsg(i18n("Exporting..."));  if(m_doc->isEmpty()) {    slotStatusMsg(i18n("Ready."));    return;  }  QString filename(QString::fromLatin1("bookcase2bibtexml.xsl"));    QString filter = i18n("*.xml|Bibtexml files (*.xml)");  filter += QString::fromLatin1("\n");  filter += i18n("*|All files");  exportUsingXSLT(filename, filter);  slotStatusMsg(i18n("Ready."));}void Bookcase::slotImportBibtex() {  slotStatusMsg(i18n("Importing from Bibtex..."));  QString filter = i18n("*.bib|Bibtex files (*.bib)");  filter += QString::fromLatin1("\n");  filter += i18n("*|All files");  // use keyword import  KURL infile = KFileDialog::getOpenURL(QString::fromLatin1(":import"), filter,                                        this, i18n("Import from Bibtex..."));  if(infile.isEmpty()) {    return;  }  QDomDocument* dom = BookcaseDoc::importBibtex(infile);  KURL url;  url.setFileName(i18n("Untitled"));  bool success = m_doc->loadDomDocument(url, *dom);  delete dom;  if(success) {    slotEnableOpenedActions(true);    slotEnableModifiedActions(true);  }  slotStatusMsg(i18n("Ready."));}void Bookcase::slotImportBibtexml() {  slotStatusMsg(i18n("Importing from Bibtexml..."));  QString filename(QString::fromLatin1("bibtexml2bookcase.xsl"));  QString xsltfile = KGlobal::dirs()->findResource("appdata", filename);  if(xsltfile.isEmpty()) {    FileError(filename);    return;  }  QString filter = i18n("*.xml|Bibtexml files (*.xml)");  filter += QString::fromLatin1("\n");  filter += i18n("*|All files");  // keyword 'import'  KURL infile = KFileDialog::getOpenURL(QString::fromLatin1(":import"), filter,                                        this, i18n("Import from Bibtexml..."));  if(infile.isEmpty()) {    return;  }    XSLTHandler handler(xsltfile);    QDomDocument* inputDom = m_doc->readDocument(infile);  // readDocument() has its own error messages  if(!inputDom || inputDom->isNull()) {    kdDebug() << "slotImportBibtexml() - null QDomDocument!" << endl;    delete inputDom;    return;  }    QString text = handler.applyStylesheet(inputDom->toString());  delete inputDom;  if(text.isEmpty()) {    XSLTError();    return;  }  QDomDocument dom;  if(!dom.setContent(text)) {    XSLTError();  }    KURL url;  url.setFileName(i18n("Untitled"));  bool success = (m_editWidget->queryModified()                  && m_doc->saveModified()                  && m_doc->loadDomDocument(url, dom));  if(success) {    slotEnableOpenedActions(true);    slotEnableModifiedActions(true);  }  slotStatusMsg(i18n("Ready."));}void Bookcase::slotExportXSLT() {  slotStatusMsg(i18n("Exporting..."));  if(m_doc->isEmpty()) {    slotStatusMsg(i18n("Ready."));    return;  }  QString filter = i18n("*.xsl|XSLT files (*.xsl)");  filter += QString::fromLatin1("\n");  filter += i18n("*|All files");  KURL xsltfile = KFileDialog::getOpenURL(QString::fromLatin1(":export"), filter,                                          this, i18n("Select XSLT file..."));  if(xsltfile.isEmpty()) {    slotStatusMsg(i18n("Ready."));    return;  }    XSLTHandler handler(xsltfile);  handler.addStringParam(QCString("version"), QCString(VERSION));  QDomDocument dom = m_doc->exportXML();  QString text = handler.applyStylesheet(dom.toString());  if(text.isEmpty()) {    XSLTError();    return;  }  KURL url = KFileDialog::getSaveURL(QString::fromLatin1(":export"),                                     i18n("*|All files"),                                     this, i18n("Export..."));  if(!url.isEmpty()) {    m_doc->writeURL(url, text);  }  slotStatusMsg(i18n("Ready."));}bool Bookcase::exportUsingXSLT(const QString& xsltFileName_, const QString& filter_) {  QString xsltfile = KGlobal::dirs()->findResource("appdata", xsltFileName_);  if(xsltfile.isEmpty()) {    FileError(xsltFileName_);    return false;  }  XSLTHandler handler(xsltfile);  handler.addStringParam(QCString("version"), QCString(VERSION));  QDomDocument dom = m_doc->exportXML();  QString text = handler.applyStylesheet(dom.toString());  if(text.isEmpty()) {    XSLTError();    return false;  }  // use keyword 'export'  KURL url = KFileDialog::getSaveURL(QString::fromLatin1(":export"), filter_,                                     this, i18n("Export..."));  if(url.isEmpty()) {    return false;  }  return m_doc->writeURL(url, text);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -