QRect KstGfxMouseHandlerUtils::newLine(const QPoint& pos, const QPoint& mouseOrigin, bool specialAspect, const QRect& bounds) {

  if (KDE_ISLIKELY(!specialAspect)) {
    QPoint npos = KstGfxMouseHandlerUtils::findNearestPtOnLine(mouseOrigin, pos, pos, bounds);
    return QRect(mouseOrigin, npos);
  } else { //want special 45deg, or vertical, or horizontal line. 
    QPoint npos;
    QPoint mouseDisplacement(pos - mouseOrigin); // for picking type of line..

    if (mouseDisplacement.x() == 0) { // vertical line.
      npos = findNearestPtOnLine(mouseOrigin, mouseOrigin + QPoint(0,1), pos, bounds);
    } else if (mouseDisplacement.y() == 0) { // horizontal line.
      npos = findNearestPtOnLine(mouseOrigin, mouseOrigin + QPoint(1,0), pos, bounds);
    } else { // 45deg or vertical or horizontal.
      int dx = int(rint(2.0*mouseDisplacement.x()/abs(mouseDisplacement.y())));
      int dy = int(rint(2.0*mouseDisplacement.y()/abs(mouseDisplacement.x())));

      if (dx != 0) {
        dx /= abs(dx);
      }
      if (dy != 0) { // type of line picked.
        dy /= abs(dy);
      }

      npos = findNearestPtOnLine(mouseOrigin, mouseOrigin + QPoint(dx,dy), pos, bounds);
    }
    return QRect(mouseOrigin, npos);
  }
}
示例#2
0
int MergeView::pluralFormsAvailableBackward()
{
    if(KDE_ISLIKELY( m_pos.entry==-1 || !m_mergeCatalog->isPlural(m_pos.entry) ))
        return -1;

    DocPosition pos=m_pos;
    while (--(pos.form)>=0)
    {
        if (m_baseCatalog->msgstr(pos)!=m_mergeCatalog->msgstr(pos))
            return pos.form;
    }
    return -1;
}
示例#3
0
int MergeView::pluralFormsAvailableForward()
{
    if(KDE_ISLIKELY( m_pos.entry==-1 || !m_mergeCatalog->isPlural(m_pos.entry) ))
        return -1;

    int formLimit=qMin(m_baseCatalog->numberOfPluralForms(),m_mergeCatalog->numberOfPluralForms());//just sanity check
    DocPosition pos=m_pos;
    while (++(pos.form)<formLimit)
    {
        if (m_baseCatalog->msgstr(pos)!=m_mergeCatalog->msgstr(pos))
            return pos.form;
    }
    return -1;
}
示例#4
0
void MergeView::mergeOpen(KUrl url)
{
    if (KDE_ISUNLIKELY( !m_baseCatalog->numberOfEntries() ))
        return;

    if (url==m_baseCatalog->url())
    {
        //(we are likely to be _mergeViewSecondary)
        //special handling: open corresponding file in the branch
        //for AutoSync

        QString path=QFileInfo(url.toLocalFile()).canonicalFilePath(); //bug 245546 regarding symlinks
        QString oldPath=path;
        path.replace(Project::instance()->poDir(),Project::instance()->branchDir());

        if (oldPath==path) //if file doesn't exist both are empty
        {
            cleanup();
            return;
        }

        url=KUrl(path);
    }

    if (url.isEmpty())
    {
        Project::instance()->model()->weaver()->suspend();
        url=KFileDialog::getOpenUrl(KUrl("kfiledialog:///merge-source") /*m_baseCatalog->url()*/ , "text/x-gettext-translation",this);
        Project::instance()->model()->weaver()->resume();
    }
    if (url.isEmpty())
        return;

    delete m_mergeCatalog;
    m_mergeCatalog=new MergeCatalog(this,m_baseCatalog);
    int errorLine=m_mergeCatalog->loadFromUrl(url);
    if (KDE_ISLIKELY( errorLine==0 ))
    {
        if (m_pos.entry>0)
            emit signalPriorChangedAvailable(m_pos.entry>m_mergeCatalog->firstChangedIndex());

        emit signalNextChangedAvailable(m_pos.entry<m_mergeCatalog->lastChangedIndex());

        //a bit hacky :)
        connect (m_mergeCatalog,SIGNAL(signalEntryModified(DocPosition)),this,SLOT(slotUpdate(DocPosition)));

        if (m_pos.entry!=-1)
            slotNewEntryDisplayed(m_pos);
        show();
    }
    else
    {
        //KMessageBox::error(this, KIO::NetAccess::lastErrorString() );
        cleanup();
        if (errorLine>0)
            KMessageBox::error(this, i18nc("@info","Error opening the file <filename>%1</filename> for synchronization, error line: %2",url.pathOrUrl(),errorLine) );
        else
        {
            /* disable this as requested by bug 272587
            KNotification* notification=new KNotification("MergeFilesOpenError", this);
            notification->setText( i18nc("@info %1 is full filename","Error opening the file <filename>%1</filename> for synchronization",url.pathOrUrl()) );
            notification->sendEvent();
            */
        }
        //i18nc("@info %1 is w/o path","No branch counterpart for <filename>%1</filename>",url.fileName()),
    }

}